1
votes

I'm fairly new to wpf and this website. Please give me some mercy if I show some mistakes.

My HierarchicalDataTemplate ,which is my treeview item, consists of multiple components: two textblocks , image , and checkbox with some stack panels for the layout. My MouseEventHandler, which is to catch when user click on textboxes, image , or checkbox , is TreeViewItem.Selected. But when I click on the tiny space between those components, it doesn't trigger TreeViewItem.Selected.

My first initial thought was that I might need to specify event handler on the stack panel which was for the layout of my HierarchicalDataTemplate . However, it didn't rise the event ,even though I made event handler on stack panel specifically.

Could you give me some guidance?

ps. I used binding for IsSelected property but it never notified to change its property

1

1 Answers

1
votes

Set Background="Transparent" for topmost layout container inside your HierarchicalDataTemplate.

The following Grid doesn't raise MouseLeftButtonDown event:

<Grid MouseLeftButtonDown="handler" Width="200" Height="200">
</Grid>

But the following does:

<Grid MouseLeftButtonDown="handler" Width="200" Height="200" Background="Transparent">
</Grid>

This is because in the 1st case it doesn't have background and there's nothing to raise MouseLeftButtonDown event. So the event will be raised only if user clicks on some element inside that Grid.