Dostępne komendy w System.Windows.Input:
Poniższy przykład pokazuje jak wykorzystać kilka wbudowanych komend i zdefiniować dla nich skróty klawiszowe:
<Window x:Class="Commands.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Window.CommandBindings> <CommandBinding Command="Favorites" CanExecute="CommandBinding_CanExecute" Executed="CommandBinding_Executed" /> <CommandBinding Command="Close" CanExecute="CommandBinding_CanExecute" Executed="CommandBinding_Executed_1" /> </Window.CommandBindings> <Window.InputBindings> <KeyBinding Command="Favorites" Key="F5" /> <KeyBinding Command="Close" Gesture="Ctrl+q" CommandParameter="q" /> </Window.InputBindings> <Grid> <CheckBox Content="myCheckbox" /> </Grid> </Window>
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = true; } private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e) { MessageBox.Show(e.Command.ToString()); } private void CommandBinding_Executed_1(object sender, ExecutedRoutedEventArgs e) { MessageBox.Show("Will be closed now"); } }
Brak komentarzy:
Prześlij komentarz