WPF ListView ,XML
Posted Fred1987
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WPF ListView ,XML相关的知识,希望对你有一定的参考价值。
<?xml version="1.0" encoding="utf-8" ?>
<PersonList>
<Person Id="1">
<Name>Fred</Name>
</Person>
<Person Id="2">
<Name>Sophie</Name>
</Person>
<Person Id="3">
<Name>FR</Name>
</Person>
<Person Id="4">
<Name>FZ</Name>
</Person>
<Person Id="5">
<Name>FY</Name>
</Person>
</PersonList>
<StackPanel>
<ListView x:Name="personListView">
<ListView.View>
<GridView>
<GridViewColumn Header="Id" Width="100" DisplayMemberBinding="{Binding [email protected]}"/>
<GridViewColumn Header="Name" Width="100" DisplayMemberBinding="{Binding XPath=Name}"/>
</GridView>
</ListView.View>
</ListView>
<Button x:Name="btn" Width="200" Height="50" Content="Click here" Click="btn_Click"/>
</StackPanel>
using System.XMl;
private void btn_Click(object sender, RoutedEventArgs e)
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(@"~\FirstXML.xml");
XmlDataProvider xdp = new XmlDataProvider();
xdp.Document = xmlDocument;
xdp.XPath = @"/PersonList/Person";
this.personListView.DataContext = xdp;
this.personListView.SetBinding(ListView.ItemsSourceProperty, new Binding());
}
以上是关于WPF ListView ,XML的主要内容,如果未能解决你的问题,请参考以下文章
wpf listview问题。给listview的每一行都加个button,button绑定该行。