views:

368

answers:

1

I have a simple WPF TreeView with icons

<TreeView Name="TreeViewThings" ItemsSource="{Binding}">
    <TreeView.Resources>
        <HierarchicalDataTemplate DataType="{x:Type local:Thing}"
                                  ItemsSource="{Binding Children}">
            <StackPanel Orientation="Horizontal" Margin="2">
                <Image Source="Thing.png" Width="16" 
                       Height="16"
                       SnapsToDevicePixels="True"/>
                <TextBlock Text="{Binding Path=Name}" Margin="5,0"/>
            </StackPanel>
        </HierarchicalDataTemplate>
    </TreeView.Resources>
</TreeView>

When a node is selected, the whole StackPanel is selected (both the image and the text). How can I restrict the selection to the Text Only?

A: 

Here is a little sth I found a while ago, when I googled for sth different: http://social.msdn.microsoft.com/forums/en-US/wpf/thread/208805b2-225f-4da3-abd7-0d3dfa92fede/

In that thread they also talk about rewriting the TreeView. You can do so like stated in this link:http://marlongrech.wordpress.com/2008/03/15/wpf-treeview-root-node/

you don't have to rewrite the TreeView class though, simply use the xaml from the latter link. you can see how to add the controltemplate if you download the source code.

Torsten