I have a treeview control in a WPF app that has 3 levels to it - Root, Child and Leaf. Something like:
<DataTemplate DataType="{x:Type local:Leaf}">
<Grid>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="True" Content="LeafCheckbox" />
<TextBlock Text="{Binding Path=SomeValue}"/>
</StackPanel>
</Grid>
</DataTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:Child}" ItemsSource="{Binding Children}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Child " />
<TextBlock Text="{Binding Path=SomeValue}" />
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:Root}" ItemsSource="{Binding Children}">
<Grid>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Root " />
<TextBlock Text="{Binding Path=SomeVa开发者_C百科lue}" />
</StackPanel>
</Grid>
</HierarchicalDataTemplate>
My design requirement has a custom header to be able to Uncheck all, like so:
After fighting this a bit, I tried adding a leaf to the first index of the bounded list with a unique name, and in the XAML treat it and skin in differently. That kind of worked, but it screwed the lists and it just became too hairy to deal with - the definition of an ugly hack. I also thought about changing the actual HierarchicalDataTemplate, having it use a grid of 2 Rows, the bottom row being that special header - that worked but the problem was that the expander would always be vertically centered and not aligned with the "Root".
Any ideas how to nicely do this?
精彩评论