Miyazaki
Miyazaki

Reputation: 1069

In WPF, how to pass a parameter to ICommand.CanExecute()

public bool SelectAll
    {
        get { return this.Get<bool>("SelectAll"); }
        set 
        {
            this.Set<bool>("SelectAll", value);
            if (this.SelectAllCommand.CanExecute(null))
                this.SelectAllCommand.Execute(value);
        }
    }

As my code, I want to a checkbox - select all function. When I manually click the "select all", I want to execute the SelectAllCommand, but if the checkbox is selected automtically, the CanExecute should return false to me....

I don't how to pass a parameter to CanExecute... How can I perfectly do that ...?

Thanks in advance

Upvotes: 0

Views: 764

Answers (1)

Tim
Tim

Reputation: 15237

Well, in your code, you're currently passing a parameter, that parameter just happens to be null. So don't you more accurately want to do

if (this.SelectAllCommand.CanExecute(value))

?

Upvotes: 1

Related Questions