using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using DevExpress.Xpf.Mvvm;
namespace TestProject
{
/// <summary>
/// 대화 상자 뷰 모델
/// </summary>
public class DialogViewModel : ViewModelBase
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 사용자명
/// </summary>
private string _strUserName;
/// <summary>
/// 대화 상자 닫기 가능 여부
/// </summary>
private bool _bCanCloseDialog = false;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Property
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 사용자명 - UserName
/// <summary>
/// 사용자명
/// </summary>
public string UserName
{
get
{
return _strUserName;
}
set
{
SetProperty(ref _strUserName, value, () => UserName);
}
}
#endregion
#region 대화 상자 닫기 가능 여부 - CanCloseDialog
/// <summary>
/// 대화 상자 닫기 가능 여부
/// </summary>
public bool CanCloseDialog
{
get
{
return _bCanCloseDialog;
}
set
{
SetProperty(ref _bCanCloseDialog, value, () => CanCloseDialog);
}
}
#endregion
#region 대화 상자 UI 명령 리스트 - DialogUICommandList
/// <summary>
/// 대화 상자 UI 명령 리스트
/// </summary>
public List<UICommand> DialogUICommandList { get; private set; }
#endregion
////////////////////////////////////////////////////////////////////////////////////////// Protected
#region Register UI 명령 - RegisterUICommand
/// <summary>
/// Register UI 명령
/// </summary>
protected UICommand RegisterUICommand { get; private set; }
#endregion
#region Cancel UI 명령 - CancelUICommand
/// <summary>
/// Cancel UI 명령
/// </summary>
protected UICommand CancelUICommand { get; private set; }
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - DialogViewModel()
/// <summary>
/// 생성자
/// </summary>
public DialogViewModel()
{
DialogUICommandList = new List<UICommand>();
RegisterUICommand = new UICommand()
{
Caption = "Register",
Command = new DelegateCommand<CancelEventArgs>(OnRegisterUICommandExecute, OnRegisterUICommandCanExecute),
IsDefault = true,
Id = MessageBoxResult.OK,
};
CancelUICommand = new UICommand()
{
Caption = "Cancel",
Command = new DelegateCommand<CancelEventArgs>(OnCancelUICommandExecute, OnCancelUICommandCanExecute),
IsCancel = true,
Id = MessageBoxResult.Cancel,
};
DialogUICommandList.Add(RegisterUICommand);
DialogUICommandList.Add(CancelUICommand);
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Register UI 명령 실행시 처리하기 - OnRegisterUICommandExecute(e)
/// <summary>
/// Register UI 명령 실행시 처리하기
/// </summary>
/// <param name="e">이벤트 인자</param>
private void OnRegisterUICommandExecute(CancelEventArgs e)
{
if(!CanCloseDialog)
{
e.Cancel = true;
}
}
#endregion
#region Register UI 명령 실행 가능 여부 조사시 처리하기 - OnRegisterUICommandCanExecute(e)
/// <summary>
/// Register UI 명령 실행 가능 여부 조사시 처리하기
/// </summary>
/// <param name="e">이벤트 인자</param>
/// <returns>Register UI 명령 실행 가능 여부</returns>
private bool OnRegisterUICommandCanExecute(CancelEventArgs e)
{
return !string.IsNullOrEmpty(UserName);
}
#endregion
#region Cancel UI 명령 실행시 처리하기 - OnCancelUICommandExecute(e)
/// <summary>
/// Cancel UI 명령 실행시 처리하기
/// </summary>
/// <param name="e">이벤트 인자</param>
private void OnCancelUICommandExecute(CancelEventArgs e)
{
if(!CanCloseDialog)
{
e.Cancel = true;
}
}
#endregion
#region Cancel UI 명령 실행 가능 여부 조사시 처리하기 - OnCancelUICommandCanExecute(e)
/// <summary>
/// Cancel UI 명령 실행 가능 여부 조사시 처리하기
/// </summary>
/// <param name="e">이벤트 인자</param>
/// <returns>Cancel UI 명령 실행 가능 여부</returns>
private bool OnCancelUICommandCanExecute(CancelEventArgs e)
{
return true;
}
#endregion
}
}