• 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中响应

  • 相关阅读:
    Run keyword if
    sublime Text如何取消两栏窗口?
    WIN7右键在目录当前打开命令行Cmd窗口
    电脑用HDMI线分屏后,耳机或音箱没声音之完美解决!
    如何解决failed to load the jni shared library问题
    APP测试点
    PHP 根据ip判断其所属地址
    thinkPHP git上传的时候,总是有些文件传不上去,.gitignore解析
    Integrity constraint violation: 1052 Column 'status' in where clause is ambiguous
    tp5导出生成pdf
  • 原文地址:https://www.cnblogs.com/gossip/p/2096699.html
Copyright © 2020-2023  润新知