PRISM의 EventAggregator가 이벤트 -> 명령 바인딩에 허용되지 않습니다.
이 경우 또 다른 옵션은 "동작"을 사용하는 것입니다. 보기 좋은 행동 Behaviors가 있습니다 : http://wpftutorial.net/Behaviors.html. 튜토리얼의 블렌드 부분은 무시할 수 있습니다. 중요한 부분은 적어도 Blend 3 SDK가 설치되어 있어야한다는 것입니다. 여기에 내가 이런 짓을하는 방법은 다음과 같습니다
public class ButtonDoubleClickCommandBehavior : Behavior<Button>
{
public ICommand DoubleClickCommand
{
get { return (ICommand)GetValue(DoubleClickCommandProperty); }
set { SetValue(DoubleClickCommandProperty, value); }
}
public static readonly DependencyProperty DoubleClickCommandProperty =
DependencyProperty.Register("DoubleClickCommand", typeof(ICommand), typeof(ButtonDoubleClickCommandBehavior));
protected override void OnAttached()
{
this.AssociatedObject.MouseDoubleClick += AssociatedObject_MouseDoubleClick;
}
protected override void OnDetaching()
{
if (this.AssociatedObject != null)
{
this.AssociatedObject.MouseDoubleClick -= AssociatedObject_MouseDoubleClick;
}
}
void AssociatedObject_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (DoubleClickCommand != null && DoubleClickCommand.CanExecute(null))
{
DoubleClickCommand.Execute(null);
}
}
}
당신은 당신이 매개 변수를 사용하여 명령을 실행할 수 있도록 명령 매개 변수를 바인딩하는 행동에 다른 종속성 속성을 추가 할 수
; 내 예제에서는 null을 사용했습니다.
그리고 내 XAML :
<Button Content="{Binding Path=Description}" VerticalAlignment="Center" HorizontalAlignment="Stretch" Template="{StaticResource TextBlockButtonTemplate}" Style="{StaticResource ZynCommandButton}" Tag="DescriptionButton">
<e:Interaction.Behaviors>
<ZViewModels:ButtonDoubleClickCommandBehavior DoubleClickCommand="{Binding Path=ItemDescriptionCommand}"/>
</e:Interaction.Behaviors>
</Button>