-
e.Handled
This just a general question. What are the places where I need to put e.Handled = true. We seem to be having events bubbling all the way up to the TabControl in the TabControl Selectionchanged event handler. So in general, whats good coding practice for placing e.Handled = true?
Thank you very much
-
Re: e.Handled
it depends entirely on your business logic.
For example, keypress events - you can handle them yourself rather than letting them go through all the way to up top. so you can indicate you handled it, and it would be stopped in processing them.
but the underlaying issue here is... why are the bubbling up? Perhaps they need to be? What is your code?
-
Re: e.Handled
First off sorry for the lack of details, like I said in the first post this is more of a general question. It's have a WPF application if that makes a difference. I think selection changed events from the Comboboxes and listboxes are bubbling all the way up to the TabControl selectionchanged event. In our code we don't check for the source of the event. Here's a code snippet to show you what am talking about:
Code:
private void tabControl1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
This Function was fired more than 20 times. So I had to put in this line of code to save the day:
Code:
if (e.OriginalSource is System.Windows.Controls.TabControl)
{
}
The tabcontrol basically consists of TabItems, each of which has a UserControl with all kinds of comboboxes, listboxes and datagrids. So I was wondering if e.Handled in the selectionchanged events for the comboboxes and listboxes would solve this problem. I also don't know the tree order when events are being bubbled. Hope this made sense. There is just too much code to post. Thanks for the prompt response. Its much appreciated.
-
Re: e.Handled
i dont believe it should be doing that, but then I have not worked with WPF but only winforms. I wouldnt expect *much* difference between those controls of the tabcontrol of WPF and Winforms.
sure you are not subscribing to the events again and again?
what if you create a CLEAN WPF app and test it with that? (just the basics)
-
Re: e.Handled
I ll try that. Thanks a bunch.
-
Re: e.Handled
How are you subscribing to the events? The bubbling/tunneling nature of WPF UI events is quite well documented - have you grasped the difference between the logical tree and the visual tree?
I would be surprised if a selection changed event was bubbling however. Have you tried relying on data binding rather than events? Using the CollectionView infrastructure will let you do whatever you need to in the bound data model rather than reacting to UI events.