locked
Binding and Button IsDefault RRS feed

  • Question

  • Anyone else nothing that if you have a button with IsDefault set and you are in the textbox bound with updatetrigger set to LostFocus when you hit Enter the button click is executed but the binding is not updated since the textbox did not lostfocus.
    Thursday, May 1, 2008 2:23 PM

Answers

  • Hi Thomas,

    Sure, the update the source explicitly would work but required additional code all over the place.

    Another way could be to capture every button click and deal with it centrally.  I was think to simply force focus on the button.  I don't see why keyboard navigation should behave differently than mouse navigation.  Click on a button using the mouse bring focus to the button so why would the Enter key not do the same.

            public App()
            {
                EventManager.RegisterClassHandler(typeof(Button), Button.ClickEvent, new RoutedEventHandler(Button_Click));
            }

            void Button_Click(object sender, RoutedEventArgs e)
            {
                if (sender != null && sender is Button)
                {
                    (sender as Button).Focus();
                }
            }
    Friday, May 2, 2008 1:33 PM
  • Hi Alex,

     

    i've just posted a short article about that. I think there's no other way than to update the source explicit:

    http://www.thomasclaudiushuber.com/blog/2008/05/02/lostfocus-textbox-vs-buttons-isdefault-property/

     

    Thomas

     

    PS: Maybe you can also tell me what you think about "half-automatic" automation properties. :-)

     -> http://www.thomasclaudiushuber.com/blog/2008/05/02/the-dream-of-half-automatic-automation-properties/

    Friday, May 2, 2008 11:22 AM

All replies

  • Hi Alex,

     

    i've just posted a short article about that. I think there's no other way than to update the source explicit:

    http://www.thomasclaudiushuber.com/blog/2008/05/02/lostfocus-textbox-vs-buttons-isdefault-property/

     

    Thomas

     

    PS: Maybe you can also tell me what you think about "half-automatic" automation properties. :-)

     -> http://www.thomasclaudiushuber.com/blog/2008/05/02/the-dream-of-half-automatic-automation-properties/

    Friday, May 2, 2008 11:22 AM
  • Hi Thomas,

    Sure, the update the source explicitly would work but required additional code all over the place.

    Another way could be to capture every button click and deal with it centrally.  I was think to simply force focus on the button.  I don't see why keyboard navigation should behave differently than mouse navigation.  Click on a button using the mouse bring focus to the button so why would the Enter key not do the same.

            public App()
            {
                EventManager.RegisterClassHandler(typeof(Button), Button.ClickEvent, new RoutedEventHandler(Button_Click));
            }

            void Button_Click(object sender, RoutedEventArgs e)
            {
                if (sender != null && sender is Button)
                {
                    (sender as Button).Focus();
                }
            }
    Friday, May 2, 2008 1:33 PM
  • Why you don't want to use UpdateSourceTrigger=PropertyChanged?
    Thursday, June 2, 2011 12:37 PM