zoukankan      html  css  js  c++  java
  • 【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中调用事件的参数了

      

  • 相关阅读:
    高斯消元法
    DP:Making the Grade(POJ 3666)
    Heap:Sunscreen(POJ 3614)
    ShortestPath:Silver Cow Party(POJ 3268)
    ShortestPath:Wormholes(POJ 3259)
    ShortestPath:Six Degrees of Cowvin Bacon(POJ 2139)
    DP:Bridging Signals(POJ 1631)
    DP:Wooden Sticks(POJ 1065)
    Greedy:Protecting the Flowers(POJ 3262)
    Greedy:Stripes(POJ 1826)
  • 原文地址:https://www.cnblogs.com/ganbei/p/14699644.html
Copyright © 2011-2022 走看看