Thursday, February 10, 2011

How can I stop a TreeViewItem from fireing the Selected event for itself, and its parent?

I have a TreeViewItem that when Selected, calles a method. However, I am finding that when the Selected event is called, the Selected event for the parent TreeViewItem also seems to be called.

I would really rather than not happen, but I haven't been able to find any documentation telling my why this is happening in the first place.

Could someone enlighten me as to why this is happening to begin with, and perhaps how to stop it.

I am open to different objects instead of a treeviewitem, but I need to maintain the visual indication of selection.

Thanks!

PS: This is a snippet of what I have.

 <TreeViewItem IsExpanded="True" IsSelected="False"  Selected="Fire_MaxCustomer_Selected_Event">
                        <TreeViewItem.Header>
                            <TextBlock Text="{Binding Path=DisplayName}" />
                        </TreeViewItem.Header>
                        <TreeViewItem.Items>
                            <TreeViewItem Header="Orders &amp; Credits" Selected="Fire_Orders_Credits_Event" />
  • I am unable to select anything at all based on the snippet you provided. You are aware that WPF's events are routed? Selected is a Bubbling event that will bubble op the visual tree and can be consumed many times. You can prevent this by setting e.Handled to true in the eventhandler.

    Russ : I know about the event being routed, and that it bubbles up the visual tree. What I did not know, is that I could set e.Handeled = true, and that would... pop the bubble.....
    From Dabblernl

0 comments:

Post a Comment