Получение CommandTarget во время фазы Выполнено - PullRequest
1 голос
/ 09 июля 2010

Как мне получить 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...
}

1 Ответ

1 голос
/ 10 июля 2010
var target = e.Source;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...