These are chat archives for AvaloniaUI/Avalonia

10th
Jun 2015
José Manuel Nieto
@SuperJMN
Jun 10 2015 15:57
Yeeehaaaa!
what's up, dudes?
I'm kicking some code to see if I can give you some good news
José Manuel Nieto
@SuperJMN
Jun 10 2015 16:02
This message was deleted
This message was deleted
José Manuel Nieto
@SuperJMN
Jun 10 2015 16:24
I have to ask you something, @grokys
        listBox.DataTemplates = new DataTemplates
        {
            new DataTemplate<Person>(o => new Button() { Content = o.Name}),
        };
this works as expected
BUT this doesn't:
        listBox.DataTemplates = new DataTemplates
        {
            new DataTemplate(o => new Button() { Content = ((Person)o).Name}),
        };
it throws an exception
José Manuel Nieto
@SuperJMN
Jun 10 2015 16:30
Captura.PNG
the non-typed DataTemplate without the match function passes an ItemsPresenter instead of the actual data :S (of type Person)
Steven Kirk
@grokys
Jun 10 2015 18:28
ok, there's a reason for that
DataTemplate has a Match function which is called to check if the DataTemplate matches the data
when you use a DataTemplate<Person> it automatically generates the Match function for you
but you're not passing a Match so the DataTemplate is matching anything
in the template for ListBox is a ScrollViewer which contains the ItemsPresenter, i.e. ScrollViewer.Content = new ItemsPresenter()
the when you set the Content property, a DataTemplate is applied
Steven Kirk
@grokys
Jun 10 2015 18:33
so it goes up the tree looking for a DataTemplate that matches ItemsPresenter
it comes to your DataTemplate and asks it "do you handle ItemsPresenters?" and your DataTemplate says "Yes I do!"
So it passes the ItemsPresenter in and bang :fire:
does that make sense?
José Manuel Nieto
@SuperJMN
Jun 10 2015 20:48

does that make sense?

Aha! Now it has sense!

I think it's something to expect after your explaination
let me think about something
aloud
in the context of XAML, I have a XamlDataTemplate (that inherits from Perspex' DataTemplate)
Then, for example, you have a ListBox and you want to define the template for the Items. You could have something like:grinning:
<ListBox.DataTemplates>
    <XamlDataTemplate DataType="SomeType" >
    ....
   </XamlDataTemplate>
</ListBox.DataTemplates>
José Manuel Nieto
@SuperJMN
Jun 10 2015 20:53
But DataType should be optional
when you only have one DataTemplate, you should use the only one
but... then, how to match?
if you set the match function to return true always, then it will handle the ItemsPresenter!
I can only think of matching only when the data isn't of type "Control"
but I don't know which consequences could it have
(that kind of matching)
Steven Kirk
@grokys
Jun 10 2015 21:11
Sorry I don't understand?
What are you trying to do?
José Manuel Nieto
@SuperJMN
Jun 10 2015 21:20
Sorry, I wasn't here :S
Look at this XAML
<Window Width="300" Height="300" xmlns:m="model">
    <ListBox Items="{Binding Path=People}">      
        <ListBox.DataTemplates>
            <XamlDataTemplate>
                <Button Content="Hello world!" />
            </XamlDataTemplate>
        </ListBox.DataTemplates>
    </ListBox>    
</Window>
there is a special kind of DataTemplate inside: XamlDataTemplate
it inherits from DataTemplate (your type)
each DataTemplate has a Match and Build
when it comes to XamlDataTemplates, I should define a Match like this:
        Match = data =>
        {
            if (DataType == null)
            {
                return !(data is Control);
            }

            return DataType == data.GetType();
        };
this works perfectly
but the !(data is Control) part seems weak
José Manuel Nieto
@SuperJMN
Jun 10 2015 21:26
the goal of it is that, if you don't specify any DataType for the XamlDataTemplate, it will always match
that is useful when you only have one template :)
do you understand what I'm doing now?
Steven Kirk
@grokys
Jun 10 2015 21:32
Yes I think so - sorry at a bar right now, will be back home in 15 mins and can talk
Steven Kirk
@grokys
Jun 10 2015 21:42
ok, back home now
ok, so i think the only difference between Perspex and WPF in this regard is that WPF's ItemsControl has an ItemTemplate property
I have wondered if that was necessary, but I've not added it because I didn't see a compelling reason
as usually the items in a ListBox etc have a known type
so you could write:
<Window Width="300" Height="300" xmlns:m="model">
    <ListBox Items="{Binding Path=People}">      
        <ListBox.DataTemplates>
            <XamlDataTemplate Type="Person">
                <Button Content="Hello world!" />
            </XamlDataTemplate>
        </ListBox.DataTemplates>
    </ListBox>    
</Window>
and it would work
the only time you'd need a template without a type is when the items aren't the same type and don't share a base class
which personally I've never needed
Steven Kirk
@grokys
Jun 10 2015 21:49
do you follow me?
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:12
yes, yes
I understand you
Steven Kirk
@grokys
Jun 10 2015 22:13
there are a few differences from WPF here which I'm only just realising
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:13
I was trying to make the DataType optional in the case of having only one type of item
Steven Kirk
@grokys
Jun 10 2015 22:13
yeah, i agree that that is convenient
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:13
but also because I didn't want to implement the converter from string => Type
:D
Steven Kirk
@grokys
Jun 10 2015 22:13
haha
now that is no excuse ;)
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:13
now you see the full reason!
Steven Kirk
@grokys
Jun 10 2015 22:13
haha yes
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:14
but yes, right now it works
yesterday I had problems with TabControl and its items
I'm goint to test them again
Steven Kirk
@grokys
Jun 10 2015 22:14
yeah - i'm sure there are problems there
i basically got TabControl working well enough to work in the TestApp and then moved to something else!
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:15
haha, OK!
Steven Kirk
@grokys
Jun 10 2015 22:15
i've been looking at WPF DataTemplates and i'm learning some interesting things
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:15
I will see if they are inflated just right
Steven Kirk
@grokys
Jun 10 2015 22:15
<ContentControl>
    <ContentControl.Resources>
        <DataTemplate DataType="{x:Type local:Item}">
            <Label>WHAT?</Label>
        </DataTemplate>
    </ContentControl.Resources>
    <local:Item Value="Hello"/>
</ContentControl>
displays "WHAT?" as you would expect
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:16
when I see something that doesn't work, I prioritize the issue and attack it depending on my personal "work items" :)
Steven Kirk
@grokys
Jun 10 2015 22:16
sure me too
however, in WPF this:
<ContentControl>
    <ContentControl.Resources>
        <DataTemplate DataType="sys:String">
            <Label>WHAT?</Label>
        </DataTemplate>
    </ContentControl.Resources>
    <sys:String>Hello</sys:String>
</ContentControl>
displays "Hello"
so it seems you can't template System.String
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:17
:O
interesting
but why?
Steven Kirk
@grokys
Jun 10 2015 22:17
likewise:
<ContentControl>
    <ContentControl.Resources>
        <DataTemplate DataType="Label">
            <Label>WHAT?</Label>
        </DataTemplate>
    </ContentControl.Resources>
    <Label>Hello</Label>
</ContentControl>
displays "Hello" so it seems you can't template other controls
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:17
hahaha
it's a bit heavy to template other controls!
I mean, how would you want that level of wrapping?
Steven Kirk
@grokys
Jun 10 2015 22:18
i seem to remember at the beginning of perspex i didn't allow you to template other controls
but then i found a use for it
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:19
it's like saying "wherever you see an item of type Button use this (...)"
Steven Kirk
@grokys
Jun 10 2015 22:19
i need to try and remember what it was!
yeah, exactly
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:19
you're supposed to template something that doesn't have have an inherent graphic representation
Steven Kirk
@grokys
Jun 10 2015 22:20
ahhh i know what it was
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:20
and with "graphic" I mean "something that is part of the UI"
like ViewModels
what it was?
Steven Kirk
@grokys
Jun 10 2015 22:21
try going to Perspex.Controls/Templates/DataTemplateExtensions
and at the beginning of MaterializeDataTemplate add this
        if (data is Control)
        {
            return (Control)data;
        }
which is saying "if the data is already a control, don't template it - return it"
then run the test app
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:22
OK!
Steven Kirk
@grokys
Jun 10 2015 22:23
blob
see what happens?
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:24
oh dear!
yes, I see!
Steven Kirk
@grokys
Jun 10 2015 22:24
:)
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:24
what's the meaning of this effect?
Steven Kirk
@grokys
Jun 10 2015 22:25
the items in the TabControls are instances of TabItem
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:25
O_O
Steven Kirk
@grokys
Jun 10 2015 22:25
the tab strip at the top is a simple selecting listbox which displays the items
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:25
argghhh!
magical trick!
at least, it sounds like a trick!
Steven Kirk
@grokys
Jun 10 2015 22:26
in the area below the tab items, i have a content control whose Content is set to TabString.SelectedItem
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:26
but I don't know how TabControls should work in terms of composition, so I can be wrong
Steven Kirk
@grokys
Jun 10 2015 22:26
well, i'm not saying the way it works is the best way ;)
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:27
haha, OK. So... TabControls aren't like ListBoxes
from what I understand
Steven Kirk
@grokys
Jun 10 2015 22:27
so anyway, the ContentControl templates TabItem to display the tab content instead of the tab control
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:28
I get a brief idea of what's happening
but I have to take a look at how controls are templated
Steven Kirk
@grokys
Jun 10 2015 22:28
this may be completely brain-dead but it's how it works right now ;)
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:28
the whole styling thing in Perspex is magic for me
OK!
for the moment, I will test the TabControl in XAML
to see if the items inside are inflated OK
let me check
Steven Kirk
@grokys
Jun 10 2015 22:29
ok yeah, let me know of any problems
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:29
(yesterday it didn't work)
Steven Kirk
@grokys
Jun 10 2015 22:29
make sure you remove the code I just told you to add though! ;)
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:29
(but I have changed a lot of stuff)
haha, don't worry. I have a pristine copy!
I usually have 3 VS instances open at the same time!
<Window Width="300" Height="300" xmlns:m="model">
    <StackPanel>
        <TabControl>
            <TabItem Header="One" />
            <TabItem Header="Two" />
            <TabItem Header="Three" />
        </TabControl>
    </StackPanel>
</Window>
Haha! works!
Steven Kirk
@grokys
Jun 10 2015 22:33
cool!
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:34
Captura.PNG
it inflates just right
by the way
I'm sure you would like the part of the "deferred" XAML loading
it's delicious!
I used the Decorator pattern to allow templates to be caught and replayed
it's great, clean and the best thing is that it works!
without that feature, the Templates wouldn't work
I will show you the XAML that works
(with templates)
Steven Kirk
@grokys
Jun 10 2015 22:38
cool! so wasn't as difficult as you feared?
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:39
it had complex parts
the main part wasn't so difficult (seeing that it could be implemented using a Decorator)
basically you wrap an object assembler into the template-aware decorator
it intercepts every instruction to the original objectAssembler
but when the node that is going to be written is a template, it just records it
(it's not written to the original object assembler)
then, when the template finished, it collects every node that has been written as part of the template and injects it into the deferred loader
then, the loader receives the recorded nodes and can do whatever with them
Steven Kirk
@grokys
Jun 10 2015 22:43
yeah, i think i undestand
i think that makes perfect sense
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:43
if you see it working, you'll understand it 100%, I'm sure
Steven Kirk
@grokys
Jun 10 2015 22:43
if i understand you correctly i imagine that's how System.Xaml does it
or something similar
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:43
no, no
it does a very weird thing!
in fact, I think it handles it far worse
there is not adapter
it just looks if the current member to be written has a deferring writer associated with it
if it has one, the invokes the write to it
and checks if it handled the call using a "if (deferringWriter.Handled==true)"...
if the deferring writer handled the call, it just returns
so, the intercepting code is right there, in the object assembler
the deferred write feature is cluttering the design of the object assembler
2 responsibilities
  1. assemblying objects
. 2. writing nodes into a guy that records things
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:49
my approach is letting the assembler do what it knows how to do: assembling objects and nothing more
Steven Kirk
@grokys
Jun 10 2015 22:49
makes sense
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:49
you may be curious about the object assembler
Steven Kirk
@grokys
Jun 10 2015 22:49
yeah, point me to the code!
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:50
it sounds like a mysterious machine!
and it is, indeed!
Argh,I lost the connectivity!
Home connection went to hell 😞
Writing in mobile now
Steven Kirk
@grokys
Jun 10 2015 22:54
oh no :(
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:54
Well, this is the link to the code!
Be warned that is plain shit ATM
It's the only remaining part that I have to rewrite from scratch
sucks hard
Steven Kirk
@grokys
Jun 10 2015 22:57
looks good on first glance!
you've been really busy!!!
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:00
nah, it's rubbish
you can see it like CPU
you tell it to perform instructions
and it produces a result
you tell the object assembler: start object SomeObject
and after that: end object
and the result is an instance of SomeObject
the instructions are XamlNodes
a stream of them
it's the higher level structure that interprets XAML
BTW, this is the XAML that uses templates
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:05
Captura.PNG
Steven Kirk
@grokys
Jun 10 2015 23:06
cool! just need to get {x:Type} working ;)
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:06
I didn't include any binding inside the template for now because the contents inside the templates don't handle extensions for now
Steven Kirk
@grokys
Jun 10 2015 23:06
yeah, binding need writing
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:07
yes! I got it working before
but the binding works!
not inside templates
but yes :D
Steven Kirk
@grokys
Jun 10 2015 23:07
oh really? what do you use for binding?
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:07
the same syntax as in good-old WPF
look at this
Steven Kirk
@grokys
Jun 10 2015 23:07
did you write a binding library?
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:08
Captura.PNG
something like that
Steven Kirk
@grokys
Jun 10 2015 23:09
cool! i assume that you're just simply binding to a single property at the moment
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:09
DataContextChangeSynchronizer is the core around that
Steven Kirk
@grokys
Jun 10 2015 23:09
so {Binding Foo.Bar} won't work?
with change tracking and everything
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:09
no, it works!
n-level binding, too!
Steven Kirk
@grokys
Jun 10 2015 23:10
wow
where is that implemented?
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:10
inside this little folder
Steven Kirk
@grokys
Jun 10 2015 23:11
wow!
you have really been busy!!!
very impressed!
how does the conversion to IObservable<> happen?
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:12
It uses INotifyPropertyChanged
it's the base of all of the change monitorization
Steven Kirk
@grokys
Jun 10 2015 23:13
ahhh ok, so it sets the properties explicitly instead of binding them to an IObservable?
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:13
I couldn't find a better way
Yes, but observables should be even easier!
Steven Kirk
@grokys
Jun 10 2015 23:14
well just setting the properties is good enough for now!
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:14
I wanted to make it work like classic MVVM
Steven Kirk
@grokys
Jun 10 2015 23:14
IObservables will only really be needed when writing control templates i think
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:15
anyways, I thought about observables a lot
and saw some problems, I cannot remember what were them
(in ViewModels)
anyways, we could like to observables natively with a special markup extension
Steven Kirk
@grokys
Jun 10 2015 23:15
yeah, well WPF doesn't even support binding to observables
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:16
{Observe}
Steven Kirk
@grokys
Jun 10 2015 23:16
yeah
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:16
watch that!
haha
Steven Kirk
@grokys
Jun 10 2015 23:16
like i say they're really only needed for binding styles etc
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:17
I hope to have the showcases running with Perspex+OmniXAML soon
I'm already loading simple XAML
Steven Kirk
@grokys
Jun 10 2015 23:17
look forward to it!
there's still so much to do in Perspex itself
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:17
:D
Steven Kirk
@grokys
Jun 10 2015 23:18
good to know you're taking care of XAML!
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:18
as soon as it gets 90% done, I can switch and help you
good to know you're taking care of Perspex!
Steven Kirk
@grokys
Jun 10 2015 23:18
yeah - at the moment it would still be a bit difficult for anyone to help i think as so much is still broken or a work in progress
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:19
yes, it's difficult
Steven Kirk
@grokys
Jun 10 2015 23:19
implementing Menu has been really good because it's exercising pretty much every part of Perspex
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:19
even popups!
Steven Kirk
@grokys
Jun 10 2015 23:19
ha yeah
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:19
and eventing
Steven Kirk
@grokys
Jun 10 2015 23:19
input
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:19
bubbling hell
Steven Kirk
@grokys
Jun 10 2015 23:19
tab navigation
arrow key navigation
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:20
terrible! I don't want to know how complex is that
but I'm sure it's a whole lot
Steven Kirk
@grokys
Jun 10 2015 23:20
f**king ItemsControls with their ItemsPresenter in a different visual tree!
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:20
oh God...
Steven Kirk
@grokys
Jun 10 2015 23:21
so when the template is applied the ItemsPresenter doesn't actually exist
until the popup opens
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:21
popups were always a nightmare
Steven Kirk
@grokys
Jun 10 2015 23:21
yeah
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:21
I understand you, bro
and being almost alone
Steven Kirk
@grokys
Jun 10 2015 23:21
they were always a pain in WPF
i understand why
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:21
it's the hard way you're learning!
hey, I'm going to bed
Steven Kirk
@grokys
Jun 10 2015 23:22
ok good night!
and amazing work!
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:22
tomorrow I'll try to make extensions work for DataTemplates
thanks :D the project well deserves it
Steven Kirk
@grokys
Jun 10 2015 23:22
:)
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:22
Perspex with XAML, it's just like Salt and Pepper!
Steven Kirk
@grokys
Jun 10 2015 23:23
haha, push it good!
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:23
well, but Perspex is a whole f**ing framework!
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:23
hahaha
aw yeahhh
see you soon!
good night everyone :D
Steven Kirk
@grokys
Jun 10 2015 23:24
night!