These are chat archives for AvaloniaUI/Avalonia

21st
Feb 2015
Steven Kirk
@grokys
Feb 21 2015 14:18
ok, @SuperJMN - I've just committed a fix to your Window problem
the way i solved it was quite simple in the end
I added an IStyleable.StyleKey property
in Control this is declared as
    Type IStyleable.StyleKey
    {
        get { return this.GetType(); }
    }
and in Window
    Type IStyleable.StyleKey
    {
        get { return typeof(Window); }
    }
i think that should do everything we need, and it's a really simple solution
i left the selector called OfType as most of the time that's what it means ;)
José Manuel Nieto
@SuperJMN
Feb 21 2015 15:23
Woohoo! Thanks!
Richard Simpson
@RichiCoder1
Feb 21 2015 17:42
What happens when you want to inherit styles from a base control, but still have styles target your more specific control?
Steven Kirk
@grokys
Feb 21 2015 18:35
hmm indeed this won't solve that situation
at the moment, you could make it's style key the base control and then set a class on the control to apply the style
but maybe it should be something more like bool IStyleable.AcceptsStyle(Type t)
that way you can customize it how you want with minimal overhead...
José Manuel Nieto
@SuperJMN
Feb 21 2015 20:08
woohoo! thanks to your changes I have just achieved what I wanted
 var w = windowFactory.Create<MainWindow>(new Uri("MainWindow.xaml", UriKind.Relative));
with a XamlWindowFactory
public class XamlWindowFactory : IWindowFactory
{
    private readonly IXamlReader xamlReader;

    private readonly ITypeFactory typeFactory;
    private readonly IResourceProvider resourceProvider;

    public XamlWindowFactory(IXamlReader xamlReader, ITypeFactory typeFactory, IResourceProvider resourceProvider)
    {
        this.xamlReader = xamlReader;
        this.typeFactory = typeFactory;
        this.resourceProvider = resourceProvider;
    }

    public T Create<T>(Uri uri) where T : Window
    {
        using (var stream = resourceProvider.GetStream(uri))
        {
            var windowInstance = typeFactory.Create(typeof(T));
            return (T)xamlReader.Load(stream, windowInstance);
        }
    }
}
José Manuel Nieto
@SuperJMN
Feb 21 2015 20:18
this is getting very interesting
Steven Kirk
@grokys
Feb 21 2015 21:54
oh cool!
still not entirely convinced of the need for the factory, but it doesn't do any harm!
to me, that just looks like a longer way of writing new MainWindow()...
Steven Kirk
@grokys
Feb 21 2015 22:01
unless you're planning to use that in the window's InitializeComponent()
which i guess would make sense
José Manuel Nieto
@SuperJMN
Feb 21 2015 23:06
no, it does no harm
believe me, that will be very useful
I have managed to decouple the components a lot
and the complexity is almost linear
José Manuel Nieto
@SuperJMN
Feb 21 2015 23:47
Oh man...
I have just discovered why ICommand wasn't compatible with ICommand
and it's because you implemented you very own ICommand interface in Perspex!
haha, I was about to go crazy!
this returned false! var compatible = targetTypeInfo.IsAssignableFrom(sourceTypeInfo);
Steven Kirk
@grokys
Feb 21 2015 23:48
Oh is there an ICommand already available? I didn't know! We should use that one
José Manuel Nieto
@SuperJMN
Feb 21 2015 23:49
yes! it is!
PCL
it's used by RxUI
I was using a ReactiveCommand<object>
:)
Steven Kirk
@grokys
Feb 21 2015 23:50
Oh ok, I wil make perspex use that one then!
José Manuel Nieto
@SuperJMN
Feb 21 2015 23:50
that is an easy one :D
Just remove your existing Iface
and use the one in:
System.Windows.Input
Steven Kirk
@grokys
Feb 21 2015 23:52
Doh! I assumed it was part of wpf so wouldn't be available
José Manuel Nieto
@SuperJMN
Feb 21 2015 23:52
hahaha, no, ICommand is like double or it right now!
Steven Kirk
@grokys
Feb 21 2015 23:52
Should have checked
José Manuel Nieto
@SuperJMN
Feb 21 2015 23:52
an essential part of the philosophy of .NET!
no worries, I started to suspect when I typed this:
ICommand c = new ReactiveCommand<object>()
and the compiler complained!
me: "why??? ReactiveCommand implements ICommand!"
and soon I understood!
it's almost a clone!
same name, different interfaces
haha
Capture.PNG
Steven Kirk
@grokys
Feb 21 2015 23:55
Haha sorry for the confusion
José Manuel Nieto
@SuperJMN
Feb 21 2015 23:56
It's proven that I'm still awake