我在某处看到这是100%可行的混合行为,找不到示例。如何通过事件参数传递将事件绑定到ViewModel上的方法。 Silverlight 4
更好的例子是将事件参数和/或发送者作为CommandParameter传递给特定的命令。
我在某处看到这是100%可行的混合行为,找不到示例。如何通过事件参数传递将事件绑定到ViewModel上的方法。 Silverlight 4
更好的例子是将事件参数和/或发送者作为CommandParameter传递给特定的命令。
<i:Interaction.Triggers>
<i:EventTrigger EventName="SizeChanged">
<ei:CallMethodAction MethodName="WndSizeChanged"
TargetObject="{Binding}" />
</i:EventTrigger>
</i:Interaction.Triggers>
WndSizeChanged方法应该是公开的,并具有相同的签名活动delegte其订阅。
一个舒适的方式来创建行为是使用DelegateCommand方法,因为在棱镜:
这里阅读:Prism behavior
Caliburn Micro有一些很好的方法来做到这一点。
从文档:
<Button Content="Remove"
cal:Message.Attach="Remove($dataContext)" />
$eventArgs – Passes the Trigger’s EventArgs or input parameter to your Action. Note: This will be null for guard methods since the trigger hasn’t actually occurred.
$dataContext – Passes the DataContext of the element that the ActionMessage is attached to. This is very useful in Master/Detail scenarios where the ActionMessage may bubble to a parent VM but needs to carry with it the child instance to be acted upon.
$source – The actual FrameworkElement that triggered the ActionMessage to be sent.
$view - The view (usually a UserControl or Window) that is bound to the ViewModel.
$executionContext - The actions's execution context, which contains all the above information and more. This is useful in advanced scenarios.
$this - The actual ui element to which the action is attached.
这并没有真正回答问题,因为委托命令没有收到事件参数。 – McGarnagle 2013-07-30 23:11:11
您可以使用通用DelegateCommands并将事件参数作为参数 – fixagon 2013-07-31 11:54:13