Question

Here is a simple DataTemplate

<Grid.Resources>
<HierarchicalDataTemplate ItemsSource="{Binding Items}" DataType="{x:Type entities:Folder}" ItemContainerStyle="{StaticResource FileComponentItem}">
    <Grid ShowGridLines="False" HorizontalAlignment="Center">
        <TextBlock Grid.Column="0" Text="{Binding Type}" />
    </Grid>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate ...... />
</Grid.Resources>

this is applied to TreeView

<TreeView Grid.Row="1" BorderThickness="0" ItemsSource="{Binding}"  ItemContainerStyle="{StaticResource FlattenedTreeViewItem}"></TreeView>

Notice that a style FileComponentItem is applied to a template for type entities:Folder

It works, accept the style is only applied to the children of this node (Folder node). meaning, only the child nodes of Folder, will get the style (whatever items are expanded under Folder, while Folder itself remains not styled).

I would like to be able to control the style of items to which the template is applied, not the children

Was it helpful?

Solution

Look at http://blogs.msdn.com/b/mikehillberg/archive/2009/10/30/treeview-and-hierarchicaldatatemplate-step-by-step.aspx

The explanation and corresponding sample should take care of your question.

OTHER TIPS

Since you applied the style to the ItemContainer and as the name suggests it will be applied to the items it contains which in this case will be the child nodes of folder. So, you need to apply this style on your listbox or any control where this Hierarchichal data template gets applied.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top