使用HierarchicalDataTemplate递归绑定现实

XAML代码:

WPF 组织机构下拉树多选,递归绑定方式现实
<UserControl x:Class="SunCreate.CombatPlatform.Client.MultiSelOrgTree"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:ui="clr-namespace:SunCreate.CombatPlatform.Client"
             mc:Ignorable="d" 
             d:DesignHeight="25" d:DesignWidth="200">
    <Grid>
        <Button x:Name="btnSelected" Click="BtnClick" Height="25">
            <Button.Template>
                <ControlTemplate>
                    <Border Height="{TemplateBinding Property=Height}">
                        <Border.Background>
                            <ImageBrush ImageSource="/SunCreate.CombatPlatform.Client.Resources;component/Image/Face/Enter.png"/>
                        </Border.Background>
                        <TextBlock Margin="3 0 0 0" Text="{TemplateBinding Property=Tag}" Foreground="#1ba4f6" VerticalAlignment="Center"></TextBlock>
                    </Border>
                </ControlTemplate>
            </Button.Template>
        </Button>
        <Popup x:Name="popup" StaysOpen="False" PopupAnimation="Scroll" Width="280" Height="300" AllowsTransparency="True">
            <Border Background="#00234E" BorderThickness="1" BorderBrush="#224066">
                <TreeView x:Name="orgTree" >
                    <TreeView.Template>
                        <ControlTemplate>
                            <ScrollViewer HorizontalScrollBarVisibility="Auto" MinHeight="{Binding ElementName=orgTree,Path=ActualHeight}" MinWidth="{Binding ElementName=orgTree, Path=ActualWidth}">
                                <ItemsPresenter></ItemsPresenter>
                            </ScrollViewer>
                        </ControlTemplate>
                    </TreeView.Template>
                    <TreeView.ItemTemplate>
                        <HierarchicalDataTemplate DataType="{x:Type ui:MultiSelOrgTreeItemModel}" ItemsSource="{Binding Path=Nodes}"  >
                            <Border Height="25" Width="200">
                                <Grid VerticalAlignment="Center" HorizontalAlignment="Left">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="auto"></ColumnDefinition>
                                        <ColumnDefinition Width="15"></ColumnDefinition>
                                        <ColumnDefinition ></ColumnDefinition>
                                    </Grid.ColumnDefinitions>
                                    <CheckBox Visibility="{Binding Path=CheckVisiable}" Tag="{Binding}" IsChecked="{Binding Path=IsChecked, Mode=TwoWay}" Click="cxb_Node_Click" Checked="cxb_Node_Checked" Unchecked="cxb_Node_UnChecked"></CheckBox>
                                    <Image Grid.Column="1" Width="10" Height="10" Source="/SunCreate.CombatPlatform.Client.Resources;component/Image/orgIcon.png"></Image>
                                    <TextBlock Grid.Column="2" FontSize="12" VerticalAlignment="Center" Margin="10,0,0,0" x:Name="Name" Foreground="White" Text="{Binding Path=Name}"></TextBlock>
                                </Grid>
                            </Border>
                        </HierarchicalDataTemplate>
                    </TreeView.ItemTemplate>
                </TreeView>
            </Border>
        </Popup>
    </Grid>
</UserControl>
View Code

相关文章:

  • 2022-12-23
  • 2022-01-25
  • 2021-10-14
  • 2021-10-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
  • 2021-10-06
  • 2021-07-31
  • 2021-12-19
相关资源
相似解决方案