WPF ListView 分组数据绑定 TreeView递归数据绑定

本文探讨了如何在WPF应用中使用ListView进行数据分组绑定,并详细介绍了如何实现TreeView的递归数据绑定,以展示复杂层级数据结构。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

WPF窗体代码:
<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:converter="clr-namespace:FileEncryptUIWpf.Converters"
        xmlns:models="clr-namespace:FileEncryptUIWpf.Model"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="FileEncryptUIWpf.MainWindow"
        Title="MainWindow" Height="408" Width="846">
	<Window.Resources>
        <CollectionViewSource x:Key="viewSource">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="Directory"/>
            </CollectionViewSource.GroupDescriptions>
        </CollectionViewSource>
        <DataTemplate x:Key="ItemCheckboxDataTemple">
            <Grid>
                <CheckBox IsChecked="{Binding IsUIChecked, Mode=TwoWay}" />
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="ItemImageDataTemple">
            <Grid>
                <Image Margin="1" Width="33" Height="15" Source="/FileEncryptUIWpf;component/Images/new.png" Stretch="None" />
            </Grid>
        </DataTemplate>
	</Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="249*" />
            <RowDefinition Height="62*" />
        </Grid.RowDefinitions>
        <GroupBox x:Name="groupBox1">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="154" />
                    <ColumnDefinition Width="539*" />
                    <ColumnDefinition Width="119" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="40" />
                    <RowDefinition Height="40" />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Grid Grid.Row="2" Name="grid2" Grid.ColumnSpan="3">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="1*" />
                        <ColumnDefinition Width="3*" />
                    </Grid.ColumnDefinitions>
                    <TreeView Name="treeView1" HorizontalAlignment="Stretch" SelectedItemChanged="treeView1_SelectedItemChanged">
                        <TreeVie
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值