<Window (...)>
<StackPanel>
<TextBox x:Name="textBox1" />
<TextBox x:Name="textBox2" />
<Button Command="ApplicationCommands.Cut" Content="Cut" />
<Button Command="ApplicationCommands.Paste" Content="Paste" />
</StackPanel>
</Window>
<Window (...)>
<Window.CommandBindings>
<CommandBinding Command="ApplicadionCommands.Cut" CanExecute="IsCutExecuteable" Executed="OnCut">
<Window.CommandBindings>
<StackPanel>
<TextBox x:Name="textBox" />
<Button Command="ApplicationCommands.Cut" Content="Cut" />
<Button Command="ApplicationCommands.Paste" Content="Paste" />
</StackPanel>
</Window>
if(ApplicationCommands.Cut.CanExecute(param))
{
ApplicationCommands.Cut.Execute(param, textBox);
}
public static class MyControlCommands
{
private static RoutedCommand UpdateTextCommand { get; } = new RoutedCommand();
}
<Button Command="local:MyControlCommands.UpdateTextCommand"
CommandParameter="Hello World!"
Content="Click me" />
public MyControl()
{
CommandBindings.Add(new CommandBinding(MyControlCommands.UpdateTextCommand, OnUpdateText, CanUpdateTextExecute));
}
private void OnUpdateText(object sender, ExecutedRoutedEventArgs args)
{
// ...
)
private bool CanUpdateTextExecute(object sender, CanExecuteRoutedEventArgs e)
{
var paramater = e.Parameter;
if(parameter != null)
e.CanExecute = true;
}