address book by mvvm pattern
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user