«« Parsing XAML with Code In It Dynamically RSS Feed Changes »»
blog header image
Changing Object Nesting in XAML

One of the really nice things about XUL was the ability to move XML representing the GUI elements like textboxes, list, etc. around quickly, even between different nesting levels, to get the layout right. Writing XUL is a really quick way to whip up prototypes of GUIs, especially since it can be skinned to look exactly like native Win32 apps.

I don't know if MS will be promoting XAML has a way to layout GUIs. There will probably be a really nice WYSIWYG editor in Visual Studio that the hardcore developers will never use but is handy for RAD. But in any case, XAML does allow for a really nice presentation/functionality seperation between XAML and code. Define how it's layed out in XAML and how it works in code, is how you could do it.

The problem I see is when you start fooling around with the nesting levels or even move objects around the GUI. Think of each nesting level as an object that contains instances of other objects that are nested inside of it. You want to fool around with your XAML code and move an object up one nesting level but now the XAML doesn't correspond with the code and the compiler chokes.

So I guess it depends on what their intentions are for XAML in the context of GUIs/Avalon. If they intend developers to layout GUIs with it like XUL then they might want to offer some refactoring support in Visual Studio that detects the change in nesting or movement in the XAML and changes the code to correspond with those movements.

Otherwise I could see keeping your XAML and code straight and corresponding being a huge problem, especially for large or complicated UI layouts.

Posted at November 13, 2003 at 10:31 AM EST
Last updated November 13, 2003 at 10:31 AM EST
Comments

I'm not sure if I understand the question but maybe I can clear this up.

think of XAML as an XML description of the heirarchy of your applications objects. This means each XML element in XAML will map to a CLR object and each XML attribute in XAML will map to a CLR property e.g.

<Window Width="640" Height="480">
  <FlowPanel>
    <TextBox ID="myTextBox">
      The initial text in a text box
    </TextBox>
    <MyNonAvalonCLRObject></MyNonAvalonCLRObject>
  </FlowPanel>
</Window>

3 things can be done with the above xml

0) It can be converted to a tokenized binary that is essentialy the same as the markup but elements and attributes are converted to tokens, this can be used to speedup download or parsing of XAML

1) It can be loaded at runtime

object uiRoot = Parser.LoadXaml(myUIAsAString);

//and inspected at runtime
Window w = uiRoot as Window;
FlowPanel f = w.Content as FlowPanel;

TextBox t = f.Children[0];
//or
TextBox t2 = SimeClassIDontRemember.FindLogicalElement(w, "myTextBox") as TextBox;

2) It can be compiled to code that is compiled and linked to an application\library

//This is off the top of my head
class MyWindow: Window
  TextBox myTextBox;
  void InitializeUI() {
    Window window_0 = new Window();
      FlowPanel flowpanel_0 = new FlowPanel();
        myTextBox = new TextBox();
        myTextBox.TextRange.Text = "The initial text in a text box"
      flowpanel_0.Children.Add(myTextBox);
      flowpanel_0.Children.Add(obj_0);
    window_0.Height = 640;
    window_0.Width = 480;
    window_0.Content = f;
  }
}

That's all nice and well but how is that relevant to refactoring your UI without refactoring your code?

In XAML when you set the ID attribute on any XML element that maps to a UIElement;
the markup compiler generates a member variable named after the ID value.
additionaly you can query the UI tree for UIElements with ID = "somestring value"

If you design your UI carefuly and only assign ID's to elements relevant to your applications logic you can refactor the UI quite a bit and never look at your code twice.

Ifeanyi Echeruo [MSFT]
SDET

This posting is provided "AS IS" with no warranties, and confers no rights.

» Posted by: Ifeanyi Echeruo at November 23, 2003 07:16 PM

That sounds a bit like DHTML, where you can assign unique IDs to your HTML elements and refer to a specific element in JavaScript, no matter where it is in the document with something like:

document.all("tagID").value;

» Posted by: Ryan at November 23, 2003 11:37 PM
Google
 
Search scope: Web ryanlowe.ca