Windows Vista Beta | WinVistaBeta.com - Message | Getting Attribute from XmlElement in XAML

August 29, 2008  
Subject: Getting Attribute from XmlElement in XAML
Group: microsoft.public.windows.developer.winfx.avalon
Date: 1/30/2008 12:43:03 PM
From: john [Email Address Protection]

All:

I am using this simple XML file as a test:

<students>
<student fname="Adam" />
<student fname="Bob" />
</students>

I have used an XmlDataProvider to bind these items to a ListBox's
ListBoxItems. This mechanism causes the ListBox to hold XmlElements.
Works fine.

I'm trying to set up a binding so that when the user selects a
ListBoxItem, the fname is displayed in a TextBox. If I make the name
part of the inner text of the item, it works OK, e.g.,

<student>Charlie</student>

The text can then be retrieved via:
<TextBox Text="{Binding SelectedItem.InnerText,
ElementName=MyStudentList}"></TextBox>

The big question is -- Is it possible in XAML to get an atttribute of
an XmlElement from the SelectedItem of a ListBox? What would the sytax
be for the binding?

Thanks,
John

Back