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"; } } }
|
'C# > WPF' 카테고리의 다른 글
[WPF] xml 16진수 값 0x0C은(는) 잘못된 문자입니다. (0) | 2020.07.08 |
---|---|
[WPF] Hyperlink (0) | 2020.07.08 |
[WPF] TextBox 개행 가능하도록 하기 (0) | 2020.07.07 |
[WPF] DispatcherObject를 상속받은 WPF의 모든 public 클래스를 트리로 보여주는 프로그램 (0) | 2020.07.07 |
[WPF] TreeView 이용하여 파일탐색기 만들기 (0) | 2020.07.07 |