Prism ObservesCanExecute in reverse

ledragonledragon Member ✭✭✭
edited November 2019 in Xamarin.Forms

Hi,

I have a property that I'm using Prism's ObservesCanExecute to prevent the command firing but I want to prevent the command when the value is true:

public DelegateCommand<RFIDto> AddIssueCommand { get; set; }

public EditIssuesViewModel(INavigationService navigationService) : base(navigationService)
{
    //Prevent command if JobCompleted
    AddIssueCommand = new DelegateCommand<RFIDto>(AddIssue, CanAddIssue).ObservesCanExecute(() => JobCompleted)
}

private bool CanAddIssue(RFIDto rfiDto = null)
{
    return !JobCompleted;
}

I've tried the following but all throw an exception when instantiating the command or won't compile:

AddIssueCommand = new DelegateCommand<RFIDto>(AddIssue, CanAddIssue).ObservesCanExecute(() => !JobCompleted);

AddIssueCommand = new DelegateCommand<RFIDto>(AddIssue, CanAddIssue).ObservesCanExecute(() => { return !JobCompleted; });

Yes I could change the property to "JobNotCompleted" (or create a new property) but I prefer not to if possible to maintain consistency with another aspect of the app.

Anyone have any ideas about how to implement?

Sign In or Register to comment.