WPF:TreeView绑定
2021-07-15 03:15
标签:open inotify ESS class public .property 数据类型 type container WPF:TreeView绑定 标签:open inotify ESS class public .property 数据类型 type container 原文地址:https://www.cnblogs.com/xpvincent/p/9525365.htmlnamespace PostViewer
{
using System.Collections.ObjectModel;
using System.ComponentModel;
///
//
UserControl x:Class="PostViewer.UcProjectTree"
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:local="clr-namespace:PostViewer"
mc:Ignorable="d"
d:DesignHeight="600" d:DesignWidth="300">
Grid>
TreeView ItemsSource="{Binding TviProjectTypes}">
TreeView.ItemContainerStyle>
Style TargetType="{x:Type TreeViewItem}">
Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
Setter Property="HorizontalContentAlignment" Value="Center" />
Setter Property="VerticalContentAlignment" Value="Center" />
Setter Property="FontWeight" Value="Normal" />
Style.Triggers>
Trigger Property="IsSelected" Value="True" >
Setter Property="FontWeight" Value="Bold" />
Trigger>
Style.Triggers>
Style>
TreeView.ItemContainerStyle>
TreeView.Resources>
HierarchicalDataTemplate DataType="{x:Type local:VmTviProjectType}" ItemsSource="{Binding TviDataTypes}">
StackPanel Orientation="Horizontal" Margin="0 2 5 0">
TextBlock Text="{Binding Header}"/>
StackPanel>
HierarchicalDataTemplate>
HierarchicalDataTemplate DataType="{x:Type local:VmTviDataType}" ItemsSource="{Binding TviDataList}">
StackPanel Orientation="Horizontal" Margin="0 2 5 0">
TextBlock Text="{Binding Header}" />
StackPanel>
HierarchicalDataTemplate>
HierarchicalDataTemplate DataType="{x:Type local:VmTviData}">
StackPanel Orientation="Horizontal" Margin="0 2 5 0">
Image Width="15" Height="15" Margin="0, 1, 0 ,0" Source="/PostViewer;component/Resources/tree_blue.png" />
TextBlock Text="{Binding Header}" />
StackPanel>
HierarchicalDataTemplate>
TreeView.Resources>
TreeView>
Grid>
UserControl>