These are chat archives for AvaloniaUI/Avalonia

10th
Jun 2015
José Manuel Nieto
@SuperJMN
Jun 10 2015 15:57 UTC
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 UTC
This message was deleted
This message was deleted
José Manuel Nieto
@SuperJMN
Jun 10 2015 16:24 UTC
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 UTC
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 UTC
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 UTC
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 UTC

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 UTC
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 UTC
Sorry I don't understand?
What are you trying to do?
José Manuel Nieto
@SuperJMN
Jun 10 2015 21:20 UTC
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 UTC
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 UTC
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 UTC
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 UTC
do you follow me?
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:12 UTC
yes, yes
I understand you
Steven Kirk
@grokys
Jun 10 2015 22:13 UTC
there are a few differences from WPF here which I'm only just realising
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:13 UTC
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 UTC
yeah, i agree that that is convenient
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:13 UTC
but also because I didn't want to implement the converter from string => Type
:D
Steven Kirk
@grokys
Jun 10 2015 22:13 UTC
haha
now that is no excuse ;)
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:13 UTC
now you see the full reason!
Steven Kirk
@grokys
Jun 10 2015 22:13 UTC
haha yes
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:14 UTC
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 UTC
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 UTC
haha, OK!
Steven Kirk
@grokys
Jun 10 2015 22:15 UTC
i've been looking at WPF DataTemplates and i'm learning some interesting things
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:15 UTC
I will see if they are inflated just right
Steven Kirk
@grokys
Jun 10 2015 22:15 UTC
<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 UTC
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 UTC
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 UTC
:O
interesting
but why?
Steven Kirk
@grokys
Jun 10 2015 22:17 UTC
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 UTC
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 UTC
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 UTC
it's like saying "wherever you see an item of type Button use this (...)"
Steven Kirk
@grokys
Jun 10 2015 22:19 UTC
i need to try and remember what it was!
yeah, exactly
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:19 UTC
you're supposed to template something that doesn't have have an inherent graphic representation
Steven Kirk
@grokys
Jun 10 2015 22:20 UTC
ahhh i know what it was
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:20 UTC
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 UTC
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 UTC
OK!
Steven Kirk
@grokys
Jun 10 2015 22:23 UTC
blob
see what happens?
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:24 UTC
oh dear!
yes, I see!
Steven Kirk
@grokys
Jun 10 2015 22:24 UTC
:)
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:24 UTC
what's the meaning of this effect?
Steven Kirk
@grokys
Jun 10 2015 22:25 UTC
the items in the TabControls are instances of TabItem
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:25 UTC
O_O
Steven Kirk
@grokys
Jun 10 2015 22:25 UTC
the tab strip at the top is a simple selecting listbox which displays the items
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:25 UTC
argghhh!
magical trick!
at least, it sounds like a trick!
Steven Kirk
@grokys
Jun 10 2015 22:26 UTC
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 UTC
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 UTC
well, i'm not saying the way it works is the best way ;)
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:27 UTC
haha, OK. So... TabControls aren't like ListBoxes
from what I understand
Steven Kirk
@grokys
Jun 10 2015 22:27 UTC
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 UTC
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 UTC
this may be completely brain-dead but it's how it works right now ;)
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:28 UTC
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 UTC
ok yeah, let me know of any problems
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:29 UTC
(yesterday it didn't work)
Steven Kirk
@grokys
Jun 10 2015 22:29 UTC
make sure you remove the code I just told you to add though! ;)
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:29 UTC
(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 UTC
cool!
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:34 UTC
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 UTC
cool! so wasn't as difficult as you feared?
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:39 UTC
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 UTC
yeah, i think i undestand
i think that makes perfect sense
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:43 UTC
if you see it working, you'll understand it 100%, I'm sure
Steven Kirk
@grokys
Jun 10 2015 22:43 UTC
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 UTC
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 UTC
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 UTC
makes sense
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:49 UTC
you may be curious about the object assembler
Steven Kirk
@grokys
Jun 10 2015 22:49 UTC
yeah, point me to the code!
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:50 UTC
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 UTC
oh no :(
José Manuel Nieto
@SuperJMN
Jun 10 2015 22:54 UTC
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 UTC
looks good on first glance!
you've been really busy!!!
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:00 UTC
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 UTC
Captura.PNG
Steven Kirk
@grokys
Jun 10 2015 23:06 UTC
cool! just need to get {x:Type} working ;)
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:06 UTC
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 UTC
yeah, binding need writing
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:07 UTC
yes! I got it working before
but the binding works!
not inside templates
but yes :D
Steven Kirk
@grokys
Jun 10 2015 23:07 UTC
oh really? what do you use for binding?
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:07 UTC
the same syntax as in good-old WPF
look at this
Steven Kirk
@grokys
Jun 10 2015 23:07 UTC
did you write a binding library?
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:08 UTC
Captura.PNG
something like that
Steven Kirk
@grokys
Jun 10 2015 23:09 UTC
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 UTC
DataContextChangeSynchronizer is the core around that
Steven Kirk
@grokys
Jun 10 2015 23:09 UTC
so {Binding Foo.Bar} won't work?
with change tracking and everything
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:09 UTC
no, it works!
n-level binding, too!
Steven Kirk
@grokys
Jun 10 2015 23:10 UTC
wow
where is that implemented?
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:10 UTC
inside this little folder
Steven Kirk
@grokys
Jun 10 2015 23:11 UTC
wow!
you have really been busy!!!
very impressed!
how does the conversion to IObservable<> happen?
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:12 UTC
It uses INotifyPropertyChanged
it's the base of all of the change monitorization
Steven Kirk
@grokys
Jun 10 2015 23:13 UTC
ahhh ok, so it sets the properties explicitly instead of binding them to an IObservable?
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:13 UTC
I couldn't find a better way
Yes, but observables should be even easier!
Steven Kirk
@grokys
Jun 10 2015 23:14 UTC
well just setting the properties is good enough for now!
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:14 UTC
I wanted to make it work like classic MVVM
Steven Kirk
@grokys
Jun 10 2015 23:14 UTC
IObservables will only really be needed when writing control templates i think
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:15 UTC
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 UTC
yeah, well WPF doesn't even support binding to observables
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:16 UTC
{Observe}
Steven Kirk
@grokys
Jun 10 2015 23:16 UTC
yeah
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:16 UTC
watch that!
haha
Steven Kirk
@grokys
Jun 10 2015 23:16 UTC
like i say they're really only needed for binding styles etc
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:17 UTC
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 UTC
look forward to it!
there's still so much to do in Perspex itself
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:17 UTC
:D
Steven Kirk
@grokys
Jun 10 2015 23:18 UTC
good to know you're taking care of XAML!
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:18 UTC
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 UTC
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 UTC
yes, it's difficult
Steven Kirk
@grokys
Jun 10 2015 23:19 UTC
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 UTC
even popups!
Steven Kirk
@grokys
Jun 10 2015 23:19 UTC
ha yeah
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:19 UTC
and eventing
Steven Kirk
@grokys
Jun 10 2015 23:19 UTC
input
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:19 UTC
bubbling hell
Steven Kirk
@grokys
Jun 10 2015 23:19 UTC
tab navigation
arrow key navigation
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:20 UTC
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 UTC
f**king ItemsControls with their ItemsPresenter in a different visual tree!
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:20 UTC
oh God...
Steven Kirk
@grokys
Jun 10 2015 23:21 UTC
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 UTC
popups were always a nightmare
Steven Kirk
@grokys
Jun 10 2015 23:21 UTC
yeah
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:21 UTC
I understand you, bro
and being almost alone
Steven Kirk
@grokys
Jun 10 2015 23:21 UTC
they were always a pain in WPF
i understand why
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:21 UTC
it's the hard way you're learning!
hey, I'm going to bed
Steven Kirk
@grokys
Jun 10 2015 23:22 UTC
ok good night!
and amazing work!
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:22 UTC
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 UTC
:)
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:22 UTC
Perspex with XAML, it's just like Salt and Pepper!
Steven Kirk
@grokys
Jun 10 2015 23:23 UTC
haha, push it good!
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:23 UTC
well, but Perspex is a whole f**ing framework!
José Manuel Nieto
@SuperJMN
Jun 10 2015 23:23 UTC
hahaha
aw yeahhh
see you soon!
good night everyone :D
Steven Kirk
@grokys
Jun 10 2015 23:24 UTC
night!