Pergunta

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!

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top