简体   繁体   中英

How do I store TreeViewItem ToggleButton, similar to TreeViewItem Header object?

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!

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM