I have a TreeView which contains mixture of different levels of TreeViewItem's.
Below works perfectly:
<TreeViewItem Tag="Link" MouseDoubleClick="TreeViewItem_MouseDoubleClick">
<TreeViewItem.Header>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Link" Margin="0 0 5 0"/>
<TextBlock Text="Link"/>
</StackPanel>
</TreeViewItem.Header>
</TreeViewItem>
But when it comes to ones where they have a TreeViewItem.Header I'm not able to set the MouseDoubleClick event correctly, see below:
<TreeViewItem IsExpanded="True" MouseDoubleClick="TreeViewItem_MouseDoubleClick">
<TreeViewItem.Header>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="HelpCircleOutline" Margin="0 0 5 0"/>
<TextBlock Text="Help" FontWeight="Bold"/>
</StackPanel>
</TreeViewItem.Header>
<ContentControl>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="BookOpenOutline" Margin="0 0 5 0"/>
<TextBlock Text="Technical Guide"/>
</StackPanel>
</ContentControl>
</TreeViewItem>
Issue with the above is that it triggers on both the Help header and the Technical Guide child.
I cannot add the event onto the <StackPanel> as it doesn't support it, so I wrapped it with <ContentControl> and tried adding the event to that, but it doesn't seem to trigger at all.
Is there any way of only having the "Technical Guide" triggering the event, but also adding in the Tag="" property as per the first code snippet as I am checking for that value in the TreeViewItem_MouseDoubleClick event?
EDIT
As requested providing code for the MouseDoubleClick event:
private void TreeViewItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (sender is TreeViewItem item)
{
var header = item.Tag as string;
switch (header)
{
case "Link":
//Open new window code
break;
}
}
Yes, you if you set the
Backgroundproperty toTransparentand handle theMouseLeftButtonDownevent and check theClickCountproperty of theMouseButtonEventArgs:XAML: