[WPF] Custom RoutedUICommand 만들기
Custom RoutedUICommand 를 만드는 코드로
Ctrl+K 를 누른 경우 TextBox 에 'kjun.kr' 이 찍히도록 하는 예시코드입니다.
using System.Windows; using System.Windows.Input;
namespace WpfApp { /// <summary> /// MainWindow.xaml에 대한 상호 작용 논리 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent();
this.textBox.AcceptsReturn = true; this.textBox.AcceptsTab = true;
InputGestureCollection inputGestureCollection = new InputGestureCollection(); inputGestureCollection.Add(new KeyGesture(Key.K, ModifierKeys.Control));
RoutedUICommand commandKjunkr = new RoutedUICommand("kjun.kr", "kjunkr", GetType(), inputGestureCollection); CommandBindings.Add(new CommandBinding(commandKjunkr, KjunkrOnExecute)); }
void KjunkrOnExecute(object sender, ExecutedRoutedEventArgs args) { this.textBox.SelectedText = "kjun.kr"; } } }
|