These are chat archives for AvaloniaUI/Avalonia

20th
Jan 2015
Steven Kirk
@grokys
Jan 20 2015 10:19
hmm, well go with the way you think best then.
the non-xaml versions just use a lambda to create the template
they don't clone the tree
and WPF/silverlight/WinRT as far as I can tell all use the XamlDeferringReader
so you'd have to invent from scratch the cloning
José Manuel Nieto
@SuperJMN
Jan 20 2015 10:50
I'll invent something!
thanks for the advice :smile:
If someone wants to help me with it, just tell me
José Manuel Nieto
@SuperJMN
Jan 20 2015 18:06
I've published a question in Stack Overflow
thinking out loud: If I follow the Single Responsibility Principle, then there should be a class that takes a VisualTree and generates another based on it
but that type should then know how to copy from N different kinds of nodes that can compose the Tree
Unless there is a CopierFactory, that is given each node and returns a copier for that type
for each node, get a copier from the copierFactory(type)
and invoke its "Copy" method
Steven Kirk
@grokys
Jan 20 2015 18:16
ok...
the thing is how are you going to do the copy?
by property using reflection? because that won't copy attached properties
what about default values? a DP can have a default value but also can be explicitly set to that value
inheritance?
i really suspect that WPF etc used the XamlDeferringReader for a reason
as it explains how to go from an object's default state -> new state
my suggestion if you don't want to use XamlDeferringReader would be to store how to get to the new state
rather than cloning the tree
Steven Kirk
@grokys
Jan 20 2015 18:22
look at say the FontSize property
that can be set at a default value, can be set locally or can be inherited from its parent control
you'd need to be sure you handled that correctly
but if you just store the delta from the default state (as does XamlDeferringReader) you don't have to worry about that
you know to set FontSize on this control
and the rest of it is handled by the property system
the idea of cloning controls doesn't really exist in XAML frameworks as far as i can see
José Manuel Nieto
@SuperJMN
Jan 20 2015 18:26
Yes, I won't clone it, but replicate it applying the necessary changes
Steven Kirk
@grokys
Jan 20 2015 18:27
yeah, i think that's what you'd have to do
which is what XamlDeferringReader does i assume
José Manuel Nieto
@SuperJMN
Jan 20 2015 18:28
With your DataTemplate, that's not a problem because you have the lambda that generates the Visual Tree
Steven Kirk
@grokys
Jan 20 2015 18:28
yes
that's how DataTemplates work in WPF and silverlight too
except that they don't use lambdas
they use XAML
or more precicely i assume, an in-memory representation of the xaml template
to clone the tree, every control would have to implement ICloneable and control authors would have to think about that behaviour, which would be a pain
José Manuel Nieto
@SuperJMN
Jan 20 2015 18:29
Hey, can you please tell me what's the name if the type in Perspex to traverse a Visual Tree?
Of*
Steven Kirk
@grokys
Jan 20 2015 18:31
visual or logical tree?
José Manuel Nieto
@SuperJMN
Jan 20 2015 18:31
Uhmm, Logical :)
Steven Kirk
@grokys
Jan 20 2015 18:32
for visual tree, include Perspex.Visual
Steven Kirk
@grokys
Jan 20 2015 18:32
that will give you extension methods for traversing
José Manuel Nieto
@SuperJMN
Jan 20 2015 18:32
THANKS!
"why don't you use DataTemplates?"
Haha 😆
Steven Kirk
@grokys
Jan 20 2015 18:33
exactly my question ;)
DataTemplates = XamlDeferringReader ;)
José Manuel Nieto
@SuperJMN
Jan 20 2015 18:33
But I cannot use it
Steven Kirk
@grokys
Jan 20 2015 18:34
but anyway, for logical tree you currently must cast to ILogical
there are no extensions written yet for that
José Manuel Nieto
@SuperJMN
Jan 20 2015 18:34
How that would be?
Steven Kirk
@grokys
Jan 20 2015 18:34
I still don't understand why you can't use XamlDeferringReader
José Manuel Nieto
@SuperJMN
Jan 20 2015 18:34
Because I don't have access to a XamlReader
And I don't think it's a good idea to carry a reader inside
Steven Kirk
@grokys
Jan 20 2015 18:36
so you're not using System.Xaml any more?
José Manuel Nieto
@SuperJMN
Jan 20 2015 18:36
Why would you need a XamlReader? The Xaml has already been inflated
Yes, only to load the XAML
The very first time
I mean, WPF does it, but it doesn't mean it's correct
Steven Kirk
@grokys
Jan 20 2015 18:38
not just WPF, System.Xaml
José Manuel Nieto
@SuperJMN
Jan 20 2015 18:38
Once the XAML is read, you shouldn't use the reader any more
Yes, and that is a big design issue, I think
The whole assembly is entangled badly
Steven Kirk
@grokys
Jan 20 2015 18:39
yeah, but if you're using it you might as well use it IMO
but anyway
José Manuel Nieto
@SuperJMN
Jan 20 2015 18:40
No if that means I have to clutter classes with a reader that doesn't make sense
Steven Kirk
@grokys
Jan 20 2015 18:40
isn't it all handled automatically though by just putting an attribute on a property?
    [Ambient]
    [XamlDeferLoad(typeof(TemplateContentLoader), typeof(TemplateContent))]
José Manuel Nieto
@SuperJMN
Jan 20 2015 18:41
That is not portable
So, denied
Steven Kirk
@grokys
Jan 20 2015 18:41
but it would be in XamlDataTemplate?
which itself isn't portable
José Manuel Nieto
@SuperJMN
Jan 20 2015 18:41
Yes, it is
I'm thinking big
Anything that can be portable, is portable
The only thing that is not, is XamlReader and their colleagues
Its
Steven Kirk
@grokys
Jan 20 2015 18:43
hmm oookkkk.... you've lost me ;)
confused
so is the plan to rewrite a portable version of System.Xaml?
maybe i should just stop asking questions and let you get on with it! i'm sure you'll make the right decisions in the end!
José Manuel Nieto
@SuperJMN
Jan 20 2015 18:47
Hahaha
Wait, my gf wants something
Steven Kirk
@grokys
Jan 20 2015 18:48
sure :) no problem - i'm just curious for your big plans
i see why stuff like ContentAttribute must be portable - as it needs to be applied to controls in a PCL
but XamlDataTemplate is a data template that loads from XAML... so I'd think that its only useful to assemblies that are non-portable as System.Xaml is non-portable
Steven Kirk
@grokys
Jan 20 2015 18:55
and unless you're planning on writing a whole XAML parser
there are 2 things that can happen:
  1. System.Xaml remains closed source and non-portable so XamlDataTemplate remains tied to non-PCL System.Xaml
  1. System.Xaml is open sourced/becomes portable in which case you can use that
arrgh gitter won't let me change that second 1. to 2.
sorry, if i'm not making much sense
i think i'm just very confused ;)
José Manuel Nieto
@SuperJMN
Jan 20 2015 18:59
The idea is to make everything portable
including the XamlReader
this is why I think big
it's not a big deal for now
Steven Kirk
@grokys
Jan 20 2015 19:01
the thing i don't userstand is... if XamlReader is made portable, then you can use XamlDeferLoad
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:01
yes! but the design will be as bad as it is in WPF
Steven Kirk
@grokys
Jan 20 2015 19:01
ok, so it's purely that you don't like the design of System.Xaml
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:01
why do you have to work with a reader after everything is read?
and moreover, it does make the code more tightly attached to one of the types that are not portable yet
Steven Kirk
@grokys
Jan 20 2015 19:02
are you sure it needs to read the XAML a second time?
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:02
I don't know
and I don't mind
Steven Kirk
@grokys
Jan 20 2015 19:02
i kind of assumed that it would read the XAML and store it in some sort of data structure
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:03
yes, the Tree itself
once it's loaded, the hydrated objects are there
I feel a lot more comfortable if the template belongs to Perspex
Steven Kirk
@grokys
Jan 20 2015 19:04
ok, i think i understand
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:04
I mean, if the template takes what it has to replicate
and it knows how to do it
the think is that I've seen while looking at the code that WPF employs a lot of deferred loads that require a stream
and that has a lot of sense when loading the XAML code
but I don't fully undertand why a templated content has to take a reader
Steven Kirk
@grokys
Jan 20 2015 19:07
but what what i see in avalonia, it doesn't
it's just decorated with an attribute
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:07
I see more appropiate something like: hey you, this is the map: now, for each foundation you have to build the same house
yes, it's automatic
following up with the example: the constructor doesn't make the same house, based on the map
the map is the template
I feel that more natural
take this house and build more houses like it along the street
Steven Kirk
@grokys
Jan 20 2015 19:09
ok, so you want a kind of runtime Datatemplate that could be used by anything
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:10
yes
if you think it again, it's more like you do with the lambda
you have the seed
each time the lamda is called, a new house appears
Steven Kirk
@grokys
Jan 20 2015 19:10
ok, that makes sense
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:10
the lambda is the prototype
return new Control...
the template is inflated by the XamlReader
I have it
Steven Kirk
@grokys
Jan 20 2015 19:11
the thing i'm worried about though, is that you're working on the wrong level of abstraction
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:11
why do you think that?
Steven Kirk
@grokys
Jan 20 2015 19:11
because IDataTemplate is the contract to do as you say
and that may be implemented in any number of ways
one of them being from a XAML file
now: if your ReflectionDataTemplate or whatever you call it
is useful elsewhere then i agree it would be a good thing to have
but are you sure you aren't generalizing too early?
i don't know the answer to that by the way!
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:13
hahaha
I don't think so
Steven Kirk
@grokys
Jan 20 2015 19:14
ok!
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:14
When you give a XAML file to the XamlReader, it does a lot of work for you
I thought about DataTemplates
is a DataTemplate something different from the rest of the objects?
I think so
but how could you say that to the XamlReader?
it could be better to treat everything in a homogeneous way, I thought
so, why don't I just create an object that inherits from DataTemplate and let the XamlReader fill it for me?
yes, I have that
but once you have it loaded, you have to wire it with the rest of the "Perspex world"
in that world, templates don't understand more than lambdas
and that is GREAT
so, in order to connect the Build lambda
with the content I'm given
I have to return something x
that x is a Logic Tree
(good punctualization -Logic!))
so... how do I feed the hungry Build lambda con a tree?
I do only have one!!
and this is how I came to this situation
Maybe I'm completely wrong
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:19
currently, this is the shitty XamlDataTemplate

using System;
using Perspex.Xaml.Base;
using Perspex.Xaml.Base.Attributes;

namespace Perspex.Controls
{
[ContentProperty("Content")]
public class XamlDataTemplate : DataTemplate
{
private Control content;
private readonly IPerspexObjectCloner perspexObjectCloner;

    public XamlDataTemplate(IPerspexObjectCloner perspexObjectCloner)
    {
        this.perspexObjectCloner = perspexObjectCloner;
        Match = o => o.GetType().Name == "Person";

        Build = item =>
        {
            var clone = perspexObjectCloner.Clone(content);
            clone.DataContext = item;

            return (Control) clone;
        };
    }

    public Type TargetType { get; set; }

    public Control Content
    {
        get
        {
            return content;
        }
        set
        {
            content = value;
        }
    }
}

}

ignore the names
the "cloner" receives the content (a Logic? tree) and retrieves a copy
clean and clear
also, the DataContext if the clone is se to the item itself (that is huge powah!)
Steven Kirk
@grokys
Jan 20 2015 19:22
in my mind - and this is my fault for not implementing it - there would be an IDataTemplate interface
so XamlDataTemplate wouldn't inherit from Datatemplate, but they would both implement IDataTemplate
i thought it was like that already in the code
but it's not, sorry :(
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:23
how that would be defined?
Steven Kirk
@grokys
Jan 20 2015 19:23
and then XamlDataTemplate would look like the DataTemplate in Avalonia
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:24
if you do that, the no Build would be possible for them :S
I prefer the way it is
Steven Kirk
@grokys
Jan 20 2015 19:24
interface IDataTemplate { bool Match(object o); Control Build(object o); }
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:25
it's almost the same you are doing now :)
Steven Kirk
@grokys
Jan 20 2015 19:26
yeah
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:26
by the way, I didn't see your example on how to traverse the logical tree
Steven Kirk
@grokys
Jan 20 2015 19:26
ok, one sec let me do a proper look
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:26
OK!
thanks!
Steven Kirk
@grokys
Jan 20 2015 19:27
ok, in Perspex.SceneGraph there's an interface Perspex.ILogical
that is similar to Perspex.IVisual in the same assembly
there are a bunch of extension methods defined for the visual tree in Perspex.SceneGraph - Perspex.VisualTree.VisualExtensions
that you access by using Perspex.VisualTree
there will be the same for the logical tree when i've implemented them
but the logical tree stuff is still very new
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:31
ahh, OK
but you can traverse the tree, can't you?
Steven Kirk
@grokys
Jan 20 2015 19:31
yeah, but i'm still unsure about how to handle ItemsControls
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:32
haha
I hope it's not a problem for the moment!
Steven Kirk
@grokys
Jan 20 2015 19:32
i hope not - it may be a problem for TabControls
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:33
and if you have a Grid, for instance, how would you get the children?
Steven Kirk
@grokys
Jan 20 2015 19:33
((ILogical)grid).LogicalChildren
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:33
nice!
Steven Kirk
@grokys
Jan 20 2015 19:33
or when the extension method is written: using Perspex.LogicalTree; grid.GetLogicalChildren()
i thnk i will add the IDataTemplate interface now as it should be there
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:39
I will do some tests!
Steven Kirk
@grokys
Jan 20 2015 19:52
ok, i've added IDataTemplate and some logical tree extension methods
José Manuel Nieto
@SuperJMN
Jan 20 2015 19:59
already uploaded?!
Steven Kirk
@grokys
Jan 20 2015 19:59
yeah
José Manuel Nieto
@SuperJMN
Jan 20 2015 20:00
oh my...!
that's quick!
I'll try to take a look after the dinner
Steven Kirk
@grokys
Jan 20 2015 20:00
they were easy changes!
José Manuel Nieto
@SuperJMN
Jan 20 2015 20:00
almost everything is easy when you have a superior mind!
artist and top developer!
Steven Kirk
@grokys
Jan 20 2015 20:01
haha
José Manuel Nieto
@SuperJMN
Jan 20 2015 20:01
by the way, how is your video going?
Steven Kirk
@grokys
Jan 20 2015 20:01
i just finished it!
now i should have some more time
José Manuel Nieto
@SuperJMN
Jan 20 2015 20:01
hey, is it uploaded online?
I wanna watchhhhh
Steven Kirk
@grokys
Jan 20 2015 20:02
not yet - i have to wait for the record label to upload and publicise it
José Manuel Nieto
@SuperJMN
Jan 20 2015 20:02
tell us when it's online :D
Steven Kirk
@grokys
Jan 20 2015 20:02
will do!
José Manuel Nieto
@SuperJMN
Jan 20 2015 20:03
it will be great to see the star of Perspex hitting the stage
and playing some good song
Steven Kirk
@grokys
Jan 20 2015 20:03
ha you will be disappointed - i'm not in the video
it's all animated
badly ;)
José Manuel Nieto
@SuperJMN
Jan 20 2015 20:03
haahaha
OK
now it's clear why you put animations to perspex before ICommands!
Steven Kirk
@grokys
Jan 20 2015 20:04
haha totally! :)
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:19
hey, is there any method that adds a Logical Child?
Steven Kirk
@grokys
Jan 20 2015 21:20
No, that depends on the control like in wpf etc
ILogical so far is just for iterating
It could be extended for adding or removing I guess
But what happens if you try to add two controls to e.g. a ContentControl?
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:22
Oh, the thing is
Is there any Visual that contains children apart from Panels?
I could just cast to Panel
and if it's not a panel, then skip it
I'm replicating the parent
and then, the children
but after the replication, I have to attach the children to the parent
how is that done in Perspex? (sorry, but I don't know!)
panel.Children.Add?
Steven Kirk
@grokys
Jan 20 2015 21:27
yeah, there's Decorator, Border, ContentControl
Window
then there will be stuff like UserControl
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:29
sure! but then there isn't an abstract method that can add a child to a parent, is it?
Steven Kirk
@grokys
Jan 20 2015 21:29
no, because the method of defining child controls is different for each type
for Window you have Window.Content
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:30
aha, that's a problem
Steven Kirk
@grokys
Jan 20 2015 21:30
where you can only have 1 logical child
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:30
for content controls, there is a Content
for Panel, Children
Steven Kirk
@grokys
Jan 20 2015 21:30
yeah
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:30
that is what I was referring to
Steven Kirk
@grokys
Jan 20 2015 21:30
what do you do iff you say: window.LogicalChildren.Add(control1); window.LogicalChildren.Add(control2);
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:30
I would like to have a single abstracted method to add a child to a parent
OperationNotSupportedException
Steven Kirk
@grokys
Jan 20 2015 21:31
it could certainly be done... but something feels wrong to me...
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:31
I don't know if that's a flaglant violation of LSP
It does smells bad to me, too
Steven Kirk
@grokys
Jan 20 2015 21:32
you have the ContentAttribute which should tell the markup parser where to add content
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:32
anyways, there sould be a method that can add a child or set the content
the cardinality is 1 => 1 or 1 => N
Steven Kirk
@grokys
Jan 20 2015 21:33
thing is, that's not needed by xaml - xaml knows where to add children
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:33
yes, but I don't know if Content == Children
I mean
ContentAttribute defines the content
at least in XAML
but, is that equivalent to define where the subordinates will be placed?
maybe I could ask if the Content Property is IEnumerable
if so, enumerate it
otherwise, it's get/set
Steven Kirk
@grokys
Jan 20 2015 21:36
enumerate it?
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:37
yes, Content, for instance
Steven Kirk
@grokys
Jan 20 2015 21:37
i thought you wanted to set it?
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:37
is not enumerable
yes, but I mean, to enumerate the children
uhmm, sorry, I have many things in mind and I have to sort them!
Steven Kirk
@grokys
Jan 20 2015 21:37
but to enumerate the child controls you use ILogical
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:38
uhmm
Steven Kirk
@grokys
Jan 20 2015 21:38
thing is for example ContentControl.Content can be anything
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:38
yes, I know that
let me think
Steven Kirk
@grokys
Jan 20 2015 21:38
it can be a string
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:39
if you get the logical children of a ContentControl
you get zero or one items
is this OK?
Steven Kirk
@grokys
Jan 20 2015 21:39
yes
but
if the child of ContentControl is a string
and there's no DataTemplate
then the LogicalChildren will be a TextBlock
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:40
aha, nice
that sounds a cool behavior ;)
Steven Kirk
@grokys
Jan 20 2015 21:40
if there is a DataTemplate then it will be whatever the root of that DataTemplate is
yeah, it's going a bit further than WPF where the Logical tree ends with a ContentControl I believe
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:41
OK, the main problem here is that there isn's a single way to set the child/children of a node
Steven Kirk
@grokys
Jan 20 2015 21:41
similarly the logical children of an ItemsControl with array of strings will be a collection of TextBlocks
no, because it depends on the control like i say
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:42
you can enumerate children, but you cannot add them using a single abstract "add child"
Steven Kirk
@grokys
Jan 20 2015 21:42
no, and I can't understand why you'd want to...
because you should know from ContentAttribute where to add stuff
if you can't add the type declared in XAML to the property with ContentAttribute then it would be a XAML error
the XAML editor will show that it's invalid
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:44
I will have to make some tricks
"do" is better there, I think
haha
Steven Kirk
@grokys
Jan 20 2015 21:45
I think this may be a problem with not using XamlDeferredLoader...
as that would do the checking for you
as it uses the same rules as the XAML parser
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:45
haha, that loaderrr
it will kill you!
:)
the XamlDeferredLoader is full of venom
Steven Kirk
@grokys
Jan 20 2015 21:46
i disagree, but i'm not going to convince you I know
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:46
hahahaha
do you like to introduce dependencies?
Steven Kirk
@grokys
Jan 20 2015 21:46
i think you're setting yourself up for a whole load of unnecessary work
you already have a dependency on the xaml loader
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:47
well, it's not just another dependency
Steven Kirk
@grokys
Jan 20 2015 21:47
I think that your problem is that you had a mental image of how templates would work
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:47
it's a BAD dependency that conditions the design
Steven Kirk
@grokys
Jan 20 2015 21:48
and now you've found that they don't work like that, your mental image doesn't want to change
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:48
haaha, but it's true! it's a design that has so many lacks
I would like to amend it, as far as I can
If you tell me how to use the XamlDeferredReader, I will use it
Steven Kirk
@grokys
Jan 20 2015 21:49
it's easy
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:49
how?
my attitude would be this:
get it working, even if you don't like it
then once you understand how it all works
try and make it better
José Manuel Nieto
@SuperJMN
Jan 20 2015 21:53
not sure, but OK
I will try to make it work
Steven Kirk
@grokys
Jan 20 2015 21:54
i mean - that's how I'd do it
because at the moment, neither of is quite sure what we're doing
;)
things can easily be changed once they're working
at this point, NOTHING is set in stone!!!!
Steven Kirk
@grokys
Jan 20 2015 22:04
also, i would be interested to know if the deferred loader did do a read of the XAML for each template instantiation
i doubt it