using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Xml; namespace readxml_1005 { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Button_Click4(object sender, RoutedEventArgs e) { XmlDocument doc = new XmlDocument(); doc.Load("RawData.xml"); XmlDataProvider xdp = new XmlDataProvider(); xdp.Document = doc; xdp.XPath = @"/StudentList/Student"; this.listViewStudents2.DataContext = xdp; this.listViewStudents2.SetBinding(ListView.ItemsSourceProperty, new Binding()); } } }MainWindow.xaml.cs
<Window x:Class="readxml_1005.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:readxml_1005" mc:Ignorable="d" Title="MainWindow" Height="300" Width="500"> <StackPanel Grid.Row="0" Grid.Column="2"> <ListView x:Name="listViewStudents2" Margin="5"> <ListView.View> <GridView> <GridViewColumn Header="Id" Width="80" displayMemberBinding="{Binding XPath=@Id}"></GridViewColumn> <GridViewColumn Header="Name" Width="120" displayMemberBinding="{Binding XPath=Name}"></GridViewColumn> <GridViewColumn Header="Age" Width="120" displayMemberBinding="{Binding XPath=Age}"></GridViewColumn> </GridView> </ListView.View> </ListView> <Button Content="Load" Click="Button_Click4" Height="25" Margin="5,0"></Button> </StackPanel> </Window>MainWindow.xaml
<?xml version="1.0" encoding="utf-8" ?> <StudentList> <Student Id = "1"> <Name>Tim</Name> <Age>28</Age> </Student> <Student Id = "2"> <Name>Tom</Name> <Age>29</Age> </Student> <Student Id = "2"> <Name>Vina</Name> <Age>30</Age> </Student> <Student Id = "3"> <Name>Emily</Name> <Age>31</Age> </Student> </StudentList>student.xml
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。