Ничего не понял. Опять вслепую. Если нужна возможность выделять элементы, то нужно заменить ItemsControl
на ListBox
. Придётся добавить триггер для скрытия списка в случае нуля элементов, потому что ListBox
, а отличие от ItemsControl
, по умолчанию рисует границу, и пустой список будет выглядеть не очень красиво.
<Window x:Class="WpfApplication1.MainWindow" x:Name="root"
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:WpfApplication1"
mc:Ignorable="d">
<Control.Resources>
<DataTemplate x:Key="tplItemRect" DataType="{x:Type local:Item}">
<Rectangle Width="6" Height="6" Stroke="DeepSkyBlue"/>
</DataTemplate>
<ItemsPanelTemplate x:Key="tplHorizontal">
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:Item}" ItemsSource="{Binding Items}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Title}" Margin="0 0 10 0"/>
<ListBox x:Name="lstItems" ItemsSource="{Binding Items}"
ItemTemplate="{StaticResource tplItemRect}"
ItemsPanel="{StaticResource tplHorizontal}"/>
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Items.Count}" Value="0">
<Setter TargetName="lstItems" Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</DataTemplate.Triggers>
</HierarchicalDataTemplate>
</Control.Resources>
<TreeView ItemsSource="{Binding Root.Items, ElementName=root}"/>
</Window>
Выглядеть будет так:

Если вам нужно выделять элементы (либо один, либо несколько), можно сделать чекбоксы или радиобатоны:
<Window x:Class="WpfApplication1.MainWindow" x:Name="root"
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:WpfApplication1"
mc:Ignorable="d">
<Control.Resources>
<DataTemplate x:Key="tplItemCheck" DataType="{x:Type local:Item}">
<CheckBox/>
</DataTemplate>
<ItemsPanelTemplate x:Key="tplHorizontal">
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:Item}" ItemsSource="{Binding Items}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Title}" Margin="0 0 10 0"/>
<ItemsControl ItemsSource="{Binding Items}"
ItemTemplate="{StaticResource tplItemCheck}"
ItemsPanel="{StaticResource tplHorizontal}"/>
</StackPanel>
</HierarchicalDataTemplate>
</Control.Resources>
<TreeView ItemsSource="{Binding Root.Items, ElementName=root}"/>
</Window>
Выглядеть будет так:

Хотя почему не поместить чекбоксы прямо в элементы — я не понял.