«« New Music Changing Object Nesting in XAML »»
blog header image
Parsing XAML with Code In It Dynamically

Watching people learn about Longhorn technology and actually discuss it with Microsoft employees is pretty far out. It'll probably take months for people to digest and ask about all of the details.

An interesting topic that came up was the notion of "dynamic" XAML, comparing to dynamic HTML. After HTML has been interpreted by the page renderer, JavaScript can alter the DOM tree of the displayed page by inserting or taking away DOM elements representing HTML. Then the renderer shows the new DOM tree and it appears as though HTML has been added or taken away.

When XAML and/or code is compiled you get bytecode. Object properties can be defined in either the XAML or code and are combined during compilation to arrive at one defined object (incidentally, which has precendence?). The question is, after the program is compiled can compiled code insert more XAML into the "XAML DOM tree"? (which doesn't actually exist after compilation if it ever did) And the answer is no yes.

Update: What Chris said was that you can't use def:Code fragments in XAML parsed by code. I was a bit confused there. :)

I have turned this large post into two because it covers different topics.

Posted at November 13, 2003 at 02:42 AM EST
Last updated November 13, 2003 at 02:42 AM EST
Comments

>> The question is, after the program is compiled can compiled code insert more XAML into the "XAML DOM tree"? (which doesn't actually exist after compilation if it ever did) And the answer is no, says Chris.

That isn't right. When an event happens (a button Click, the Page Loaded event happens, etc...) you can have code run. The tree of Elements is fully dynamic.

You can create new Elements: Button b1 = new Button(); //in C#

You can add those elements to the tree:
if a DockPanel had an ID of "dp1", you'd say dp1.Children.Add(b1); //to add the new button into the dockpanel's children collection.

You can remove elements.
You can move elements.
etc...

DHTML brought the ability to have declarative markup and to change the tree during runtime (without a navigation) -- Avalon is not a step backwards here at all.

» Posted by: Rob Relyea at November 13, 2003 08:41 AM

Ahh, well that's good. :)

» Posted by: Ryan at November 13, 2003 08:57 AM
Google
 
Search scope: Web ryanlowe.ca