views:

43

answers:

2

I have the following XML being set on my treeview:

<Root Value="YES">
 <Child Name="Test">
 <Sibling Data="Yes">
  <Last UserData="1"/>
 </Sibling>
 <Sibling Data="No"/>
 </Child>
 <Child Name="Test2"/>
</Root>

and then I have set the following code in my window:

<Window.Resources>
    <XmlDataProvider x:Key="dataProvider" XPath="Root" Source="C:\XML.xml" />

    <HierarchicalDataTemplate DataType="Root" ItemsSource="{Binding XPath=*}">
      <TextBlock Text="{Binding XPath=@Value}" />

      <HierarchicalDataTemplate.ItemContainerStyle>
        <Style TargetType="{x:Type TreeViewItem}">
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate>
                <Border Background="Blue">
                  <ContentPresenter/>
                </Border>
              </ControlTemplate>
            </Setter.Value>
          </Setter>
        </Style>
      </HierarchicalDataTemplate.ItemContainerStyle>
    </HierarchicalDataTemplate>

    <HierarchicalDataTemplate DataType="Child" ItemsSource="{Binding XPath=*}">
      <TextBlock Text="{Binding XPath=@Name}" />
    </HierarchicalDataTemplate>

    <HierarchicalDataTemplate DataType="Sibling" ItemsSource="{Binding XPath=*}">
      <TextBlock Text="{Binding XPath=@Data}" />
    </HierarchicalDataTemplate>
  </Window.Resources>

  <Grid>
    <TreeView Margin="12" x:Name="trv"
         ItemsSource="{Binding Source={StaticResource dataProvider}}" />
  </Grid>

I would like to have a border control wrap around all the subitems for every node as in this image:

http://www.hardcodet.net/uploads/2008/03/tree-dialogik.png

In other words, you'll notice in the image I've linked to, the parent node dialogik.Memory has a dark gray border that goes around it and around its children. That's the effect I want to achieve.

What do I need to change in my code to have it work correctly ???

Thanks !!

A: 

That's not possible with the TreeView. You could use an Expander though, see here:

http://msdn.microsoft.com/en-us/library/system.windows.controls.expander.aspx

..and then bind it similarly: you'd have an ItemsControl that outputs an Expander for each item, and the Expander would then contain another ItemsControl for child items, recursively.

Hope that helps!

Kieren Johnstone
A: 

So I guess theree is no other way than to use an Expander? That won't work for me since I'm using HierarchicalDataTemplates for my TreeView. Using an Expander in my HierarchicalDataTemplates won't work.

Thanks for the answer.

Max