Как мне получить CommandTarget в Выполненном обратном вызове RoutedCommand ?
Спасибо.
Редактировать: добавление подробного образца
Класс команд:
static class Commands
{
public static readonly RoutedCommand MyCommand = new RoutedCommand();
}
XAML код
<Window.CommandBindings>
<CommandBinding Command="{x:Static BasicWpfCommanding:Commands.MyCommand}"
CanExecute="MyCommandCanExecute"
Executed="MyCommandExecuted"/>
</Window.CommandBindings>
<StackPanel>
<Button Command="{x:Static BasicWpfCommanding:Commands.MyCommand}"
CommandParameter="#FF303030"
CommandTarget="{Binding ElementName=aButton}"
Name="aButton">A Command</Button>
</StackPanel>
Команды обратных вызовов
private void MyCommandCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
private void MyCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{
//var target = (Button)sender fires an ecception: in effect "sender" is the main window...
}