如何在wpf中绑定xml? [英] How to Binding xml in wpf?
本文介绍了如何在wpf中绑定xml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我现在有一个xml为
I now have an xml as
<Root>
<Window Width="583" Height="617">
<Group ID="Info1" Name="M1" >
<Wrap ID="1" Visibility="1">
<Parameter ID="txtName" Text="Name1" Visibility="1" />
<Parameter ID="txtName1" Visibility="1" Width="200"/>
</Wrap>
</Group>
<Group ID="Info2" Name="M2" >
<Wrap ID="1" Visibility="1">
<Parameter ID="txtcName" Text="Name2" Visibility="1" />
<Parameter ID="txtcName1" Visibility="1" Width="200"/>
</Wrap>
</Group>
</Window>
</Root>
我的xaml是
My xaml is
<Grid Name="gridCustomer">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" >
<GroupBox>
<GroupBox.Header>
<Binding XPath="@Name"></Binding> //I want to bind the Group ID for Info1 Name property
</GroupBox.Header>
<StackPanel>
<WrapPanel Margin="0,10,0,0">
<TextBlock Margin="10,0,0,0" Text="Name1" /> //I want to bind the Group ID for Info1 txtName property
<TextBox Margin="20,0,0,0" x:Name="txtName" Width="200"/>
</WrapPanel>
</StackPanel>
</GroupBox>
<GroupBox>
<GroupBox.Header>
<Binding XPath="@Name"></Binding>
</GroupBox.Header>
<StackPanel>
<WrapPanel Margin="0,10,0,0">
<TextBlock Margin="10,0,0,0" Text="Name2" />
<TextBox Margin="20,0,0,0" x:Name="txtName1" Width="200"/>
</WrapPanel>
</StackPanel>
</GroupBox>
</StackPanel>
</Grid>
我的背景代码
My background code
string path = "c://1.xml";
provider.Source = new Uri(path);
provider.XPath = @"/Root/Window/Group";
gridCustomer.DataContext = provider;
我想知道如何实现这些绑定?指定绑定到指定节点的名称
I want to know how we can achieve these bindings? Specify the name of the binding to the specified node
推荐答案
尝试以下解决方案 -
WPF:XmlDataProvider双向数据绑定 [ ^ ]
如何:使用XMLDataProvider绑定到XML数据 [ ^ ]
http://joshsmithonwpf.wordpress.com/2007/06/04/binding-to-xml / [ ^ ]
关于此主题的视频l - http://www.youtube.com/watch?v=1pVQ-VTcM18 [ ^ ]。
Try the following solutions -
WPF: XmlDataProvider Two-Way Data Binding[^]
How to: Bind to XML Data Using an XMLDataProvider[^]
http://joshsmithonwpf.wordpress.com/2007/06/04/binding-to-xml/[^]
A video on this topic as well - http://www.youtube.com/watch?v=1pVQ-VTcM18[^].
这篇关于如何在wpf中绑定xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文