728x90
반응형
728x170
▶ RelayCommand.cs
using System;
using System.Windows.Input;
/// <summary>
/// 릴레이 명령
/// </summary>
public class RelayCommand : ICommand
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Event
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 실행 가능 여부 변경시 - CanExecuteChanged
/// <summary>
/// 실행 가능 여부 변경시
/// </summary>
public event EventHandler CanExecuteChanged
{
add
{
CommandManager.RequerySuggested += value;
}
remove
{
CommandManager.RequerySuggested -= value;
}
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 실행 액션
/// </summary>
private readonly Action<object> executeAction;
/// <summary>
/// 실행 가능 여부 프레디킷
/// </summary>
private readonly Predicate<object> canExecutePredicate;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - RelayCommand(executeAction, canExecutePredicate)
/// <summary>
/// 생성자
/// </summary>
/// <param name="executeAction">실행 액션</param>
/// <param name="canExecutePredicate">실행 가능 여부 프레디킷</param>
public RelayCommand(Action<object> executeAction, Predicate<object> canExecutePredicate)
{
if(executeAction == null)
{
throw new ArgumentNullException("executeAction");
}
this.executeAction = executeAction;
this.canExecutePredicate = canExecutePredicate;
}
#endregion
#region 생성자 - RelayCommand(executeAction)
/// <summary>
/// 생성자
/// </summary>
/// <param name="executeAction">실행 액션</param>
public RelayCommand(Action<object> executeAction) : this(executeAction, null)
{
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 실행하기 - Execute(parameter)
/// <summary>
/// 실행하기
/// </summary>
/// <param name="parameter">파라미터</param>
public void Execute(object parameter)
{
this.executeAction(parameter);
}
#endregion
#region 실행 가능 여부 구하기 - CanExecute(parameter)
/// <summary>
/// 실행 가능 여부 구하기
/// </summary>
/// <param name="parameter">파라미터</param>
/// <returns>실행 가능 여부</returns>
public bool CanExecute(object parameter)
{
return this.canExecutePredicate == null ? true : this.canExecutePredicate(parameter);
}
#endregion
}
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] DataGrid 클래스 : 대용량 데이터 바인딩하기 (0) | 2021.10.03 |
---|---|
[C#/WPF/.NETCORE] FaceDetector 클래스 : DetectFacesAsync 메소드를 사용해 얼굴 탐지하기 (0) | 2021.09.23 |
[C#/WPF/.NETCORE] 누겟 설치 : Microsoft.Windows.SDK.Contracts (0) | 2021.09.23 |
[C#/WPF/.NETCORE] BitmapImage 클래스 : WINFORM Bitmap 객체에서 비트맵 이미지 구하기 (0) | 2021.09.23 |
[C#/WPF/.NETCORE] IValueConverter 인터페이스 : 비트맵→비트맵 소스 변환자 사용하기 (0) | 2021.09.23 |
[C#/WPF] ICommand 인터페이스 : 매개 변수를 갖는 대리자 명령 사용하기 (0) | 2021.09.23 |
[C#/WPF] ICommand 인터페이스 : 대리자 명령 사용하기 (0) | 2021.09.23 |
[C#/WPF] ComboBox 클래스 : 우선 순위 필터 콤보 박스 사용하기 (0) | 2021.09.17 |
[C#/WPF] 대시보드 애니메이션 사용하기 (0) | 2021.09.16 |
[C#/WPF] 확장 메뉴 사용하기 (0) | 2021.09.15 |
댓글을 달아 주세요