Results 1 to 6 of 6

Thread: e.Handled

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    56

    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

  2. #2
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    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?

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    56

    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.

  4. #4
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    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)

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    56

    Re: e.Handled

    I ll try that. Thanks a bunch.
    Last edited by samv12; Oct 5th, 2011 at 01:26 PM.

  6. #6
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width