WPF PRISM 6 DelegateComand ObservesCanExecute

Thanks in advance!

How to use ObservesCanExecute in Commomma PRISM 6 deletion?

public partial class  UserAccountsViewModel: INotifyPropertyChanged
{
    public DelegateCommand InsertCommand { get; private set; }
    public DelegateCommand UpdateCommand { get; private set; }
    public DelegateCommand DeleteCommand { get; private set; }

    public UserAccount SelectedUserAccount
    {
        get;
        set
        {
            //notify property changed stuff
        }
    }

    public UserAccountsViewModel()
    {
        InitCommands();
    }

    private void InitCommands()
    {
        InsertCommand = new DelegateCommand(Insert, CanInsert);  
        UpdateCommand = new DelegateCommand(Update,CanUpdate).ObservesCanExecute(); // ???
        DeleteCommand = new DelegateCommand(Delete,CanDelete);
    }

    //----------------------------------------------------------

    private void Update()
    {
        //...
    }

    private bool CanUpdate()
    {
        return SelectedUserAccount != null;
    }

    //.....
}

Unfortunately, I am not familiar with expressions in C #. In addition, I thought it would be useful for others.

+4
source share
1 answer

ObservesCanExecute()works "mostly like" parameter canExecuteMethod DelegateCommand(Action executeMethod, Func<bool> canExecuteMethod).

However, if you have a boolean property instead of a methodyou do not need to define canExecuteMethodwith ObservesCanExecute.

In your example, suppose CanUpdateit is not a method , just assume that it is a logical property .

ObservesCanExecute(() => CanUpdate), DelegateCommand , CanUpdate boolean true ( ).

ObservesCanExecute "" , canExecuteMethod DelegateCommand.

+7

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


All Articles