【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中调用事件的参数了

  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM