Silverlight / WPF: I do not want ICommand to change the IsEnabled property, is this possible?

So to speak, I have a button (MyButton) that binds to:

public ICommand MyCommand { get; set; }

I will register this command with

MyCommand = new DelegateCommand<object>(DoSomething);

Now if i do

MyButton.IsEnabled = false;

He does nothing, i.e. the button is still on. I know that the command calls this because if I delete the new delegate code above, the button will be disabled.

My questions:
1. Is there a way to tell me this binding to the command so as not to be confused with my IsEnabled button
2. Is there a way to change the visibility only using the command property (which would probably be a more correct way) anyway

Thank!!

+3
source share
2

CanExecute, :

ICommand comand = new DelegateCommand<object>
    (
    executeMethod: delegate { DoSomething(); }
    ,
    canExecuteMethod: delegate { return _buttonEnabled; }
    );

_buttonEnabled = false;

CommandManager.InvalidateRequerySuggested();

_buttonEnabled = true;

CommandManager.InvalidateRequerySuggested();

"_buttonEnabled" , , . , "_isSomethingDone" true\false . , "DoSomething" - .

:

ICommand saveCommand = new DelegateCommand<object>
    (
    executeMethod: delegate { Save(); }
    ,
    canExecuteMethod: delegate { return _canSave; }
    );

private void Save()
{
    _canSave = false;

    CommandManager.InvalidateRequerySuggested();

    //do save...

    _canSave = true;

    CommandManager.InvalidateRequerySuggested();
}
+3

CanExecute . , , . msdn ICommand documentation, . CanExecuteChanged() , - , .

, . , visiblity, .

+1

Source: https://habr.com/ru/post/1755842/


All Articles