zoukankan      html  css  js  c++  java
  • MVVM模式下,View触发任意事件在ViewModel中响应

       由于使用的是prism框架,所有需要首先引入Prism4\Lib\Desktop下的

    Microsoft.Expression.Interactions.dll

    System.Windows.Interactivity.dll

    XAML文件

    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"

    绑定事件

    <Button Content="MouseLeave事?件t" Width="70" Height="25">

                <i:Interaction.Triggers>

                    <i:EventTrigger EventName="MouseLeave"  >

                        <i:InvokeCommandAction Command="{Binding MouseLeave}"

                                               CommandParameter="123"/>

                    </i:EventTrigger>

                </i:Interaction.Triggers>

            </Button>

    ViewModel文件

         public ICommand MouseLeave

            {

                get

                {

                    return new DelegateCommand<string>(x =>

                    {

                        MessageBox.Show("MouseLeave" + x);

                    });

                }

            }

    注意事项:

    Microsoft.Expression.Interactions.dll

    System.Windows.Interactivity.dll

    prismC:\Program Files\Microsoft SDKs\Expression\Blend 3\Interactivity\Libraries\WPF都有,并且WPFSilverligter都有这些文件(不能通用),如果引用的是blend中的dll,则需要通过xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"方式引用,但是绑定事件的方式和从prism引用的dll不同,这些问题纠结了我半天,所以建议dllprim文件夹下引用

    Dllhttp://compositewpf.codeplex.com/下载

    MVVM模式下,View触发任意事件在ViewModel中响应

  • 相关阅读:
    netcore一键部署到linux服务器以服务方式后台运行
    查找100-999之间的水仙花数
    shell创建数据库的脚本
    python打印九九乘法表的菱形实现
    c++一些重要的细节
    MySQL数据库基础学习笔记(二)
    MySQL数据库基础学习笔记(一)
    react-redux 的基本使用
    react-router-dom基本使用+3种传参方式
    从create-react-app 项目搭建开始
  • 原文地址:https://www.cnblogs.com/gossip/p/2096699.html
Copyright © 2011-2022 走看看