XML绑定在Silverlight没有标称班 [英] Binding XML in Silverlight without nominal classes
问题描述
让我们说我有XML的简单chunck: -
Let's say I have a simple chunck of XML:-
<root>
<item forename="Fred" surname="Flintstone" />
<item forename="Barney" surname="Rubble" />
</root>
已经获取此XML在Silverlight我想用的这个ILKE的XAML : -
<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>
现在我可以使用LINQ仅仅够绑定到XML和标称等级: -
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;}
}
是否可以没有这个类来完成
Can it be done without this class?
在换句话说,Silverlight的代码与输入的XML之间的耦合被限制为仅XAML,其他源代码是不可知的该组项目元素的属性的
In other words, coupling between the Silverlight 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.
修改:使用XSD的建议,但最终它相当于同样的事情。 。XSD->生成的类
Edit: The use of XSD is suggested but ultimately it amounts the same thing. XSD->Generated class.
修改:一个匿名类不起作用,Silverlight的不能约束他们。
Edit: An anonymous class doesn't work, Silverlight can't bind them.
修改强>:这需要两个方式,用户需要能够编辑的值和这些值在XML中结束。 // grahammurray:(更改后的原始的TextBlock到文本框在样品上方)
Edit: This needs to be two way, the user needs to be able to edit the values and these values end up in the XML. (Changed original TextBlock to TextBox in sample above.)
推荐答案
请参阅的绑定到匿名类型在Silverlight 的信息。
See Binding to Anonymous types in Silverlight for information.
这篇关于XML绑定在Silverlight没有标称班的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!