These are chat archives for AvaloniaUI/Avalonia

19th
Jan 2015
José Manuel Nieto
@SuperJMN
Jan 19 2015 08:51
Good morning!
I've achieved great things with XAML!
and with DataTemplates in XAML
:smile:
what I'm facing now is the good-old problem of cloning
José Manuel Nieto
@SuperJMN
Jan 19 2015 08:56
I've read the XamlDeferringLoader
but I don't know how I could use it, since it reads the content from a XamlReader
I would like to generate copies of the VisualTree defined in the DataTemplate for each item
so I have to replicate everything!
but how?! :S
José Manuel Nieto
@SuperJMN
Jan 19 2015 09:06
how are you supposed to copy objects without knowing anything about them? :S
Steven Kirk
@grokys
Jan 19 2015 14:55
you don't have a XamlReader?
when i have some free time, i will step through the Avalonia code that impements DataTemplates and try to remember how it works
still rather busy with various things at the moment, though that should stop this week
José Manuel Nieto
@SuperJMN
Jan 19 2015 16:26

you don't have a XamlReader?

Yes, I do, but it is feed up with a Stream of that originates from a XAML-formatted string

Steven Kirk
@grokys
Jan 19 2015 16:31
sorry, i don't understand, that is the way it works in avalonia i think
have you took at look at how it's done there?
i'm pretty sure that XamlDeferringLoader is a better way to do it than cloning
José Manuel Nieto
@SuperJMN
Jan 19 2015 16:49
No, I still haven't checked it
sorry!
let me try to explain it better
after the original XAML is read, all the controls are inflated.
including a type that I created that is XamlDataTemplate (inherits from DataTemplate)
each XamlDataTemplate in the XAML will have a Content property.
whose contents are the Visual Visual tree that is defined in the XAML
so, after reading the XAML, XamlDataTemplate has a Content, that is, in fact, a Visual Tree
José Manuel Nieto
@SuperJMN
Jan 19 2015 16:54
since XamlDataTemplate is a Tamplate, it will have a Build method that is called for each item, and that method should generate the visual tree for each item
but you only have the "seed" visual tree
that is inflated. It's not XAML, but real objects
the Build method should take that seed and generate a copy of the Visual Tree
José Manuel Nieto
@SuperJMN
Jan 19 2015 17:05
that is where I'm stuck :S
José Manuel Nieto
@SuperJMN
Jan 19 2015 21:39
I'm looking into Avalonia
José Manuel Nieto
@SuperJMN
Jan 19 2015 21:54
OK, I see you use XamlNodeList.GetReader()
public class TemplateContent
{        
    internal object Load()
    {
        return Avalonia.Media.XamlReader.Load(this.nodeList.GetReader());
    }
}
José Manuel Nieto
@SuperJMN
Jan 19 2015 22:07
well, it's really strange! I have to dig more into that
José Manuel Nieto
@SuperJMN
Jan 19 2015 22:22
It seems that instead of copying a visual tree, it's using a reader to generate another
It feels a bit strange to me. Copying a VisualTree is more natural, I think
because having to use a stream introduces another point of dependency with a big and complex type (XamlReader/DeferringReader)
I think it's more elegant to have some class that is especialized. Some type that replicates a visual tree