■ CommandBinding 클래스를 사용하는 방법을 보여준다.
▶ MainWindow.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
using System; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { Title = "CommandBinding 클래스 사용하기"; Width = 800; Height = 600; FontFamily = new FontFamily("나눔고딕코딩"); FontSize = 16; Button button = new Button(); button.HorizontalAlignment = HorizontalAlignment.Center; button.VerticalAlignment = VerticalAlignment.Center; button.Padding = new Thickness(5); button.Command = ApplicationCommands.Paste; button.Content = ApplicationCommands.Paste.Text; Content = button; CommandBindings.Add ( new CommandBinding ( ApplicationCommands.Paste, Paste_Executed, Paste_CanExecute ) ); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 프로그램 시작하기 - Main() /// <summary> /// 프로그램 시작하기 /// </summary> [STAThread] public static void Main() { Application application = new Application(); application.Run(new MainWindow()); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Instance //////////////////////////////////////////////////////////////////////////////// Protected #region 마우스 다운시 처리하기 - OnMouseDown(e) /// <summary> /// 마우스 다운시 처리하기 /// </summary> /// <param name="e">이벤트 인자</param> protected override void OnMouseDown(MouseButtonEventArgs e) { base.OnMouseDown(e); Title = "CommandBinding 클래스 사용하기"; } #endregion //////////////////////////////////////////////////////////////////////////////// Private #region 붙여넣기 실행시 처리하기 - Paste_Executed(sender, e) /// <summary> /// 붙여넣기 실행시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void Paste_Executed(object sender, ExecutedRoutedEventArgs e) { Title = Clipboard.GetText(); } #endregion #region 붙여넣기 실행 가능 여부 체크시 처리하기 - Paste_CanExecute(sender, e) /// <summary> /// 붙여넣기 실행 가능 여부 체크시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void Paste_CanExecute(object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = Clipboard.ContainsText(); } #endregion } } |