我已经实施了attached command behavior pattern found here并且它很好地运作以允许例如边境到有火灾视图模型一个左或右键单击事件:如何将两个附加行为附加到一个XAML元素?
XAML:
<Border Background="Yellow" Width="350" Margin="0,0,10,0" Height="35" CornerRadius="2"
c:CommandBehavior.Event="MouseLeftButtonDown"
c:CommandBehavior.Command="{Binding PressedLeftButton}"
c:CommandBehavior.CommandParameter="MainBorder123">
<TextBlock Text="this is the click area"/>
</Border>
代码背后:
public ICommand PressedLeftButton { get; private set; }
public MainViewModel()
{
Output = "original value";
PressedLeftButton = new SimpleCommand
{
ExecuteDelegate = parameterValue => {
Output = String.Format("left mouse button was pressed at {0} and sent the parameter value \"{1}\"", DateTime.Now.ToString(), parameterValue.ToString());
}
};
}
然而,怎么办我将两个附加行为附加到一个元素,例如我想要做类似下面的,但它当然给我一个错误:
<Border Background="Yellow" Width="350" Margin="0,0,10,0" Height="35" CornerRadius="2"
c:CommandBehavior.Event="MouseLeftButtonDown"
c:CommandBehavior.Command="{Binding PressedLeftButton}"
c:CommandBehavior.CommandParameter="MainBorder123"
c:CommandBehavior.Event="MouseRightButtonDown"
c:CommandBehavior.Command="{Binding PressedRighttButton}"
c:CommandBehavior.CommandParameter="MainBorder123"
>
就是这样,谢谢,不过搞笑的是我的XAML编辑给我的错误“的附着性能‘行为’型‘CommandBehaviorCollection’没有被发现。”虽然我可以运行并编译它,但为什么呢? – 2009-05-29 15:21:48