微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决如何通过事件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.
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。