• 【WPF】将控件事件中的参数,传递到ViewModel中


    在MVVM模式下,在通常使用命令(Command)绑定的方式的时候 ,使用的是 CommandParameter 属性进行参数的传递。

    但是很多时候,有一些事件我们需要使用其中的一些事件里面的参数,以获取相关数据或状态,但是使用命令绑定的方式又没办法达到这个要求,那么如何做呢?

    1、引用相关命名空间

      

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

    2、在控件中使用命令

      

    1 <控件>
    2     <i:Interaction.Triggers>
    3     <i:EventTrigger EventName="ExportEnd">
    4       <Interaction:CallMethodAction TargetObject="{Binding}" MethodName="ExportEndCommand"/>
    5       <!--<i:InvokeCommandAction Command="{Binding ExportEndCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self} }"/>-->
    6     </i:EventTrigger>
    7   </i:Interaction.Triggers>
    8 </控件>

    3、在 ViewModel中这样写

    public void ExportEndCommand(object obj , Telerik.ReportViewer.Common.ExportEndEventArgs args)
            {
    
            }

    根据自己的事件类型,进行参数的填写。

    这样就可以在ViewModel中调用事件的参数了

      

  • 相关阅读:
    js 脚本学习 索引
    nodejs 学习索引
    oracle 学习 笔记
    githut 的 管理 使用
    sublime text 插件记录
    web 学习 相关索引
    wpf 自定义 无边框 窗体 resize 实现
    vs 效率工具
    ANDROID开发实用小工具
    iOS开发之Core Animation
  • 原文地址:https://www.cnblogs.com/ganbei/p/14699644.html
Copyright © 2020-2023  润新知