public partial class MainWindow : Window
{
public static RoutedCommand AlertCommand = new RoutedCommand();
public MainWindow()
{
InitializeComponent();
}
private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
{
System.Windows.MessageBox.Show("Hello world");
}
private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = this.checkbox.IsChecked.Value;
}
}
<Window.CommandBindings>
<CommandBinding
Command="{x:Static local:MainWindow.AlertCommand}"
Executed="CommandBinding_Executed"
CanExecute="CommandBinding_CanExecute" />
</Window.CommandBindings>
<Window.InputBindings>
<KeyBinding
Command="{x:Static local:MainWindow.AlertCommand}"
Key="A"
Modifiers="Ctrl+Alt" />
</Window.InputBindings>
<StackPanel>
<CheckBox x:Name="checkbox" Content="CanExecute" />
<Button Content="Click" Command="{x:Static local:MainWindow.AlertCommand}" />
</StackPanel>
'Windows > C#/WPF' 카테고리의 다른 글
[WPF] & 등의 이스케이프 문자 처리 (0) | 2021.05.13 |
---|---|
[WPF] 나중에 참고할 링크 (0) | 2021.05.12 |
데이터 바인딩 2 (0) | 2021.05.11 |
데이터 바인딩 1 (0) | 2021.05.09 |
리소스 & ControlTemplate (0) | 2021.05.08 |
댓글