3.WFP表格

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

 

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...