Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF TreeView - Group Nodes Style
    primarykey
    data
    text
    <p>I have a list of type IList called groups and each group has a sub list of Type IList called items. Both Group and Item have property called Name. To display this hierarchy i'm using a TreeView.</p> <p>I want to display each group in the hierarchy as an Expander, however it's not displaying as i want to.</p> <p>So far my xaml:</p> <pre><code>&lt;DataTemplate x:Key="NavItemTemplate"&gt; &lt;TextBlock Text="{Binding Name}"/&gt; &lt;/DataTemplate&gt; &lt;HierarchicalDataTemplate x:Key="NavGroupTemplate" ItemsSource="{Binding Items}" ItemTemplate="{StaticResource NavItemTemplate}"&gt; &lt;TextBlock Text="{Binding Name}"/&gt; &lt;/HierarchicalDataTemplate&gt; &lt;Style x:Key="RootItemStyle" TargetType="{x:Type TreeViewItem}"&gt; &lt;Setter Property="IsExpanded" Value="True"/&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="TreeViewItem"&gt; &lt;Grid&gt; &lt;Expander x:Name="Exp" TextElement.FontWeight="Bold" IsExpanded="{TemplateBinding TreeViewItem.IsExpanded}"&gt; &lt;Expander.Header&gt; &lt;ContentPresenter x:Name="ExpCP" ContentSource="Header"/&gt; &lt;/Expander.Header&gt; &lt;ItemsPresenter/&gt; &lt;/Expander&gt; &lt;Border x:Name="CP" Padding="25,0,0,0" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Visibility="Collapsed"&gt; &lt;ContentPresenter ContentSource="Header" HorizontalAlignment="Left" VerticalAlignment="Center" /&gt; &lt;/Border&gt; &lt;/Grid&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="HasItems" Value="false"&gt; &lt;Setter TargetName="Exp" Property="Visibility" Value="Collapsed"/&gt; &lt;Setter TargetName="CP" Property="Visibility" Value="Visible" /&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsSelected" Value="True"&gt; &lt;Setter Property="Background" Value="Red"/&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;TreeView ItemsSource="{Binding}" ItemTemplate="{StaticResource NavGroupTemplate}" ItemContainerStyle="{StaticResource RootItemStyle}"&gt; </code></pre> <p>The above style </p> <p>works for:</p> <p>Group1 (expander)</p> <ul> <li>Item1</li> </ul> <p>Group2 (expander)</p> <p>...</p> <p>but doesn't work for (the goal):</p> <p>Group1 (expander)</p> <ul> <li><p>Item1</p> <ul> <li>SubItem1</li> </ul></li> </ul> <p>Group2 (expander)</p> <p>...</p> <p>Also the above style also needs further correction. When i select the expander border side it triggers a selecteditem event, which should be prevented.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload