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.

108 lines
2.8 KiB

using AddressBook_MVVMSample.Command;
using AddressBook_MVVMSample.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace AddressBook_MVVMSample.SubWindow
{
/// <summary>
/// AddViewWindow.xaml에 대한 상호 작용 논리
/// </summary>
public partial class AddViewWindow : Window
{
public enum ViewType
{
Add,
Modify
}
public DelegateCommand OkCommand { get; set; }
public DelegateCommand CancelCommand { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
public AddViewWindow()
{
InitializeComponent();
InitInstance();
}
public AddViewWindow(Person modifyData = null, ViewType type = ViewType.Add)
{
InitializeComponent();
InitInstance(modifyData, type);
}
private void InitInstance(Person modifyData = null, ViewType type = ViewType.Add)
{
this.DataContext = this;
if (type == ViewType.Modify)
{
this.Caption = "Modify";
this.PersonData = modifyData;
}
else
{
this.Caption = "Add";
this.PersonData = new Person();
}
this.OkCommand = new DelegateCommand(CommandOkAction);
this.CancelCommand = new DelegateCommand(CommandCancelAction);
}
private string _caption = "Title";
public string Caption
{
get { return _caption; }
set
{
_caption = value;
OnPropertyChanged(nameof(Caption));
}
}
private Person _personData;
public Person PersonData
{
get { return _personData; }
set
{
_personData = value;
OnPropertyChanged(nameof(PersonData));
}
}
private void CommandOkAction(object obj)
{
this.DialogResult = true;
this.Close();
}
private void CommandCancelAction(object obj)
{
this.DialogResult = false;
this.Close();
}
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}