Question

I want to be able to access the ToggleButton in the TreeViewItem so I can add a listener to it, so that all the Items in the TreeViewItem will not inherit the listener. I know for Header you can assign to TextBlock (or whichever user control you want) then assign a listener to the TextBlock so that the items in TreeViewItem do not inherit the listener.

Pseudo-code:

 TreeViewItem.ToggleButton.MouseLeftButtonUp += new MouseButtonEventHandler(blah);

Thanks!

Was it helpful?

Solution

If I understand you correctly you want to react to event only if control to which event was attached to is invoking the event, then try:

private void Click(object sender, RoutedEventArgs e)
{
    if (e.Source == sender)
    {

    }
}

Note that there is no such thing as listeners inheritances in wpf controls events model. You might want to read more about it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top