1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| <Window x:Class="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:Testtreeview"
mc:Ignorable="d"
Title="Text treeview" Height="450" Width="300">
<Window.Resources>
<local:ConvertUnderscore x:Key="ConvertUnderscore"></local:ConvertUnderscore>
<HierarchicalDataTemplate
DataType="{x:Type local:MyClasse}"
ItemsSource="{Binding Objets}">
<StackPanel Orientation="Horizontal">
<Image Width="12" Height="12" Margin="3,0" Source="{Binding Image}" />
<Label Content="{Binding Nom}" Height ="25" Margin="3,-5,3,-5">
<Label.Style >
<Style TargetType="Label" >
<Style.Triggers>
<DataTrigger Binding="{Binding Selected_Treeview}" Value="true">
<Setter Property="Foreground" Value="Yellow" />
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate
DataType="{x:Type local:MyObject}"
ItemsSource="{Binding Attributs}">
<StackPanel Orientation="Horizontal">
<Image Width="12" Height="12" Margin="3,0" Source="{Binding Image}" />
<Label Content="{Binding Nom, Converter={StaticResource ConvertUnderscore}}" Height ="25" Margin="3,-5,3,-5">
<Label.Style >
<Style TargetType="Label" >
<Style.Triggers>
<DataTrigger Binding="{Binding Selected_Treeview}" Value="true">
<Setter Property="Foreground" Value="Yellow" />
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
<Label.ContextMenu >
<ContextMenu >
<MenuItem Header="Data" Click="MenuItem_Click" IsCheckable="False"></MenuItem>
</ContextMenu>
</Label.ContextMenu>
</Label>
</StackPanel>
</HierarchicalDataTemplate>
<DataTemplate
DataType="{x:Type local:MyAttribut}">
<StackPanel Orientation="Horizontal">
<Image Width="12" Height="12" Margin="3,0" Source="{Binding Image}" />
<Label Content="{Binding Nom}" Height ="25" Margin="3,-5,3,-5">
<Label.Style >
<Style TargetType="Label" >
<Style.Triggers>
<DataTrigger Binding="{Binding Selected_Treeview}" Value="true">
<Setter Property="Foreground" Value="Yellow" />
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
</StackPanel>
</DataTemplate>
</Window.Resources>
<StackPanel >
<TreeView
Grid.Column="0"
x:Name="tv"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Margin="10"
ItemsSource="{Binding Classes_Treeview}"
Height="350" Width=" 250"
>
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem" >
<Setter Property="FontSize" Value="10" />
<Setter Property="IsExpanded" Value="{Binding Expanded,Mode=TwoWay}"/>
<Setter Property="IsSelected" Value="{Binding Selected, Mode=TwoWay}"/>
<Style.Triggers >
<Trigger Property="IsSelected" Value="true" >
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontStyle" Value="Italic" />
<Setter Property="Foreground" Value="Yellow" />
</Trigger>
</Style.Triggers>
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
<Button x:Name="CMD_Close"
Height="40" Width="80"
Content="Close"
Command="{Binding CommandClose}"/>
</StackPanel>
</Window> |
Partager