码迷,mamicode.com
首页 > Windows程序 > 详细

WPF ListView ,XML

时间:2016-10-22 16:57:48      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:column   panel   source   void   ldo   set   1.0   dev   this   

<?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 XPath=@Id}"/>
<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

标签:column   panel   source   void   ldo   set   1.0   dev   this   

原文地址:http://www.cnblogs.com/Fred1987/p/5987625.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!