如何通过事件args将事件绑定到ViewModel上的方法 Silverlight 4

问题描述

| 我在某处看到使用混合行为100%可行,找不到示例。 更好的例子是将事件args和/或sender作为CommandParameter传递给特定命令。     

解决方法

   <i:Interaction.Triggers>
        <i:EventTrigger EventName=\"SizeChanged\">
            <ei:CallMethodAction MethodName=\"WndSizeChanged\"
                TargetObject=\"{Binding}\" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
WndSizeChanged方法应该是公共的,并且与它所订阅的事件委托具有相同的签名。     ,创建行为的一种简便方法是使用Prism中的DelegateCommand方法: 在这里阅读:棱镜行为     ,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.