2011-05-26 38 views

回答

4
<i:Interaction.Triggers> 
     <i:EventTrigger EventName="SizeChanged"> 
      <ei:CallMethodAction MethodName="WndSizeChanged" 
       TargetObject="{Binding}" /> 
     </i:EventTrigger> 
    </i:Interaction.Triggers> 

WndSizeChanged方法应该是公开的,并具有相同的签名活动delegte其订阅。

1

一个舒适的方式来创建行为是使用DelegateCommand方法,因为在棱镜:

这里阅读:Prism behavior

+0

这并没有真正回答问题,因为委托命令没有收到事件参数。 – McGarnagle 2013-07-30 23:11:11

+0

您可以使用通用DelegateCommands并将事件参数作为参数 – fixagon 2013-07-31 11:54:13

1

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. 
相关问题