Lets say I have a simple chunck of XML:-
<root>
<item forename="Fred" surname="Flintstone" />
<item forename="Barney" surname="Rubble" />
</root>
Having fetched this XML in Silverlight I would like to bind it with xaml of this ilke:-
<ListBox x:Name="ItemList" Style="{StaticResource Items}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBox Text="{Binding Forename}" />
<TextBox Text="{Binding Surname}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Now I can bind simply enough with LINQ to XML and a nominal class:-
public class Person {
public string Forename {get; set;}
public string Surname {get; set;}
}
So here is the question, can it be done without this class? IOW coupling between the Sliverlight code and the input XML is limited to the XAML only, other source code is agnostic to the set of attributes on the item element.
Edit: The use of XSD is suggested but ultimately it amounts the same thing. XSD->Generated class.
Edit: An anonymous class doesn't work, Silverlight can't bind them.
Edit: This needs to be two way, the user needs to be able to edit the values and these value end up in the XML. (Changed original TextBlock to TextBox in sample above).