You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.7 KiB

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<IDialogView, Unit>(view => FuncOkCommand(view));
this.CancelCommand = ReactiveCommand.Create<IDialogView, Unit>(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;
}
}
}