WPF-控件-层级控件-TreeView

WPF-控件-层级控件-TreeView

<?xml version="1.0" encoding="utf-8" ?>

<Data xmlns="">

  <Grade Name="一年级">

    <Class Name="1班">

      <Group Name="A组"/>

      <Group Name="B组"/>

      <Group Name="C组"/>

      <Group Name="D组"/>

    </Class>

  </Grade>

  <Grade Name="二年级">

    <Class Name="1班">

      <Group Name="A组"/>

      <Group Name="B组"/>

      <Group Name="C组"/>

      <Group Name="D组"/>

    </Class>

  </Grade>

  <Grade Name="三年级">

    <Class Name="1班">

      <Group Name="A组"/>

      <Group Name="B组"/>

      <Group Name="C组"/>

      <Group Name="D组"/>

    </Class>

  </Grade>

</Data>

 

<Window x:Class="TreeView.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="MainWindow" Height="350" Width="525">

    <Window.Resources>

        <!--数据源-->

        <XmlDataProvider x:Key="ds" Source="Data.xml" XPath="Data/Grade"/>

        <!--年级模板-->

        <HierarchicalDataTemplate DataType="Grade" ItemsSource="{Binding XPath=Class}">

            <TextBlock Text="{Binding XPath=@Name}"></TextBlock>

        </HierarchicalDataTemplate>

        <!--班级模板-->

        <HierarchicalDataTemplate DataType="Class" ItemsSource="{Binding XPath=Group}">

            <RadioButton Content="{Binding XPath=@Name}" GroupName="gn"></RadioButton>

        </HierarchicalDataTemplate>

        <!--小组模板-->

        <HierarchicalDataTemplate DataType="Group" ItemsSource="{Binding XPath=Student}">

            <CheckBox Content="{Binding XPath=@Name}"></CheckBox>

        </HierarchicalDataTemplate>

    </Window.Resources>

    <Grid>

        <TreeView ItemsSource="{Binding Source={StaticResource ds}}"></TreeView>

    </Grid>

</Window>

你可能感兴趣的:(treeview)