TextBox and default Button binding does update too late

前端 未结 3 1120
[愿得一人]
[愿得一人] 2020-11-29 09:01

I\'ve got a simple WPF dialog with these two controls:


3条回答
  •  庸人自扰
    2020-11-29 09:38

    Try this. This code moves focus on the button clicked. Thus binding completes before command processed.

        public App()
        {
            EventManager.RegisterClassHandler(typeof(Button), Button.ClickEvent, new RoutedEventHandler(GenericButtonClickHandler));
        }
    
        void GenericButtonClickHandler(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;
            if (button == null)
                return;
            if (button.IsDefault)
                button.Focus();
        }
    

提交回复
热议问题