using AddressBook_MVVMSampleV2.Interface; using AddressBook_MVVMSampleV2.Model; using ReactiveUI; using System; using System.Collections.Generic; using System.Linq; using System.Reactive; using System.Text; using System.Threading.Tasks; using System.Windows.Input; namespace AddressBook_MVVMSampleV2.ViewModel { public class AddViewModel : ReactiveObject { public enum ViewType { Add, Modify } public Person PersonData { get; set; } public ICommand OkCommand { get; private set; } public ICommand CancelCommand { get; private set; } public AddViewModel() : this(null, ViewType.Add) { } public AddViewModel(Person data = null, ViewType type = ViewType.Add) { if (type == ViewType.Modify) this.Caption = "Modifty information"; else this.Caption = "Add infomation"; this.PersonData = data; this.OkCommand = ReactiveCommand.Create(view => FuncOkCommand(view)); this.CancelCommand = ReactiveCommand.Create(view => FuncCancelCommand(view)); } private string _caption; public string Caption { get { return _caption; } set { this.RaiseAndSetIfChanged(ref _caption, value); } } private Unit FuncOkCommand(IDialogView view) { view.DialogResult = true; view.Close(); return Unit.Default; } private Unit FuncCancelCommand(IDialogView view) { view.DialogResult = false; view.Close(); return Unit.Default; } } }