Click here to Skip to main content
15,559,287 members
Please Sign up or sign in to vote.
1.22/5 (2 votes)
See more:
I was recently asked a question on how to disable a button when the View is loaded; and then enable it again when the end-user starts entering data in some textboxes. For e.g. in a WPF Search application, only if the end-user enters some text in the Search textbox, the Search button should become enabled.

My question is I find a solution for one textbox.

However in my application there are several textboxes. I want to enable the button when all textboxes are not empty. If any textbox is empty, then the button should be disabled.

The code in the link only apply one property Name.
SearchPersonCommnad = new RelayActionCommand()
                CanExecuteAction = n=> !String.IsNullOrEmpty(Name),
                 ExecuteAction = n => defaultView.Filter = name => ((PersonInfo)name).FirstName.StartsWith(Name) 
                     || ((PersonInfo)name).LastName.StartsWith(Name) 
                     || ((PersonInfo)name).City==Name

Let's say I have many properties, how to do that?

What I have tried:

There is a similar one. But it doesn't solve my question.
Updated 12-Jan-18 8:55am

1 solution

If you want to disable the command when any one of a set of properties is empty, then just update the CanExecuteAction accordingly:
CanExecuteAction = n => !string.IsNullOrEmpty(FirstProperty) && !string.IsNullOrEmpty(SecondProperty) && ...
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900