Can I do this?

May 14, 2009 at 3:30 PM

First and foremost, thank you very much for this highly useful library.

Is there a way for me to put a border around a series of nodes?

So, assuming that I have a Nodes A, B and C, and B has five sub nodes (b1-b5), is there a way to put a border just around B1-B5? It looks like to me like it would require some measure of header/footer, or at least the declaration of the rows that are to be repeated.

Currently when I use the HierarchicalDataTemplate, if I put a border around something, it obviously does it for every entry.

Thank you very much for your assistance.

Coordinator
May 14, 2009 at 5:59 PM

You can explicitly call out a template by name for your sub nodes.  Just like in the example for pickles and ice cream below:

       <HierarchicalDataTemplate DataType="{x:Type local:ClassC}">
            <HierarchicalDataTemplate.ItemsSource>
                <MultiBinding Converter="{StaticResource complex-group-converter}" ConverterParameter="Pickles-Template,IceCream-Template">
                    <Binding Path="Pickles"/>
                    <Binding Path="IceCream"/>
                </MultiBinding>
            </HierarchicalDataTemplate.ItemsSource>
            ...

        </HierarchicalDataTemplate>
        <HierarchicalDataTemplate x:Key="Pickles-Template" ItemsSource="{Binding Path=.}">
             <Border ...>

             <StackPanel Orientation="Horizontal">
                <Image Source="Images/pickles.jpg" VerticalAlignment="Center" Margin="0,5,0,5"/>
                <TextBlock  VerticalAlignment="Center"  Margin="5,0,0,0">Class C:</TextBlock>
                <TextBlock Text="{Binding Path=Label}" ToolTip="{Binding Path=ToolTip}"  VerticalAlignment="Center"  Margin="5,0,0,0"/>
            </StackPanel>
            </Border>

        </HierarchicalDataTemplate>

        <HierarchicalDataTemplate x:Key="IceCream-Template" ItemsSource="{Binding Path=.}">
             <StackPanel Orientation="Horizontal">
                <Image Source="Images/icecream.jpg" VerticalAlignment="Center" Margin="0,5,0,5"/>
                <TextBlock  VerticalAlignment="Center"  Margin="5,0,0,0">Class C:</TextBlock>
                <TextBlock Text="{Binding Path=Label}" ToolTip="{Binding Path=ToolTip}"  VerticalAlignment="Center"  Margin="5,0,0,0"/>
            </StackPanel>
        </HierarchicalDataTemplate>

May 15, 2009 at 6:03 AM

Thanks for your response, but unless I'm missing something, it doesn't do what I want. 

ClassC has both Pickles and IceCream. Now, when I expand Class C, and I expand Pickles, let's say I want to have a border around all of the items that pickles contains, but not the pickles node itself.

In the example you have above, assuming I have 3 pickles, I end up with a border around each pickle, not around the group of three pickles.

I have come close to resolving the problem by playing with the TreeViewItem Control template and putting in some data triggers. This works, but I get some confusing results.

To make this clear, I have something that looks like:

ClassA -> (List)ClassB 

This will then look like :

+ ClassA
    + ClassB

Now, when I open Class B, I retrieve a list of all the items, which is fine.  But when I open it, I want a box to be around the items in ClassB, so it should look like:

+ ClassA
   - ClassB
     --------------------------
     |  Data    Data   Data  |
     |  Data    Data   Data  |
     --------------------------

I tried putting a DataTrigger against ClassB, but since ClassB node and it's children all return ClassB, I get a border around the entire thing. I then thought I could look to see how many logical (not visual) children it has, but for some reason ClassB always returns the number of chilren available to the first child node.

This is where I get to. If this is too difficult to follow, I can arrange to send you some demo code.

Thanks for your patience.