开发者

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

开发者 https://www.devze.com 2022-12-13 13:10 出处:网络
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 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开发者_如何学JAVA 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消