There is a MainViewModel that has an ActiveLayoutItem property, which is initialized only after the Add () command, that is, when the MainViewModel constructor is initialized, this property will be null. The MainViewModel has a ReactiveCommandCheck command that has two conditions that can be executed:
- ActiveLayoutItem must be non-null and be PropertiesViewModel (ActiveLayoutItem is PropertiesViewModel)! = Null;
- (ActiveLayoutItem as PropertiesViewModel) .ReactiveCommand1.CanExecute == true;
How to implement this command?
public class MainViewModel : ViewModelBase { public ReactiveCommand<Unit, Unit> ReactiveCommandCheck { get; set; } public void RC1Ex() { this.Tools.Clear(); } public ViewModelBase ActiveLayoutItem { get { return _activeLayoutItem; } set => this.RaiseAndSetIfChanged(ref _activeLayoutItem, value); } public MainViewModel() { ReactiveCommandCheck = ReactiveCommand.Create(RC1Ex, ***??? ***); } public void Add() { var vm = new PropertiesViewModel(); ActiveLayoutItem = vm; } } public class PropertiesViewModel : ViewModelBase { public ReactiveCommand<Unit, Unit> ReactiveCommand1 { get; } public void RC1Ex() { Title = ""; } public PropertiesViewModel() { Title = "Documents Properties"; var canEx = this.WhenAnyValue( x => x.Title, x => !string.IsNullOrWhiteSpace(x)); ReactiveCommand1 = ReactiveCommand.Create(RC1Ex, canEx); } }