문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top