Using WPF Validation rules and the disabling of a 'Save' button

前端 未结 10 2098
眼角桃花
眼角桃花 2020-11-28 09:54

I have a page where a few textboxes cannot be empty before clicking a Save button.


                            


        
10条回答
  •  误落风尘
    2020-11-28 10:26

    I've tried several of the solutions stated above; however, none of them worked for me.

    My Simple Problem

    I have a simple input window that request a URI from the user, if the TextBox value isn't a valid Uri then the Okay button should be disabled.

    My Simple Solution

    Here is what worked for me:

    CommandBindings.Add(new CommandBinding(AppCommands.Okay,
                (sender, args) => DialogResult = true,
                (sender, args) => args.CanExecute = !(bool) _uriTextBoxControl.GetValue(Validation.HasErrorProperty)));
    

提交回复
热议问题