【问题标题】:passing argument with InvokeCommandAction MVVM使用 InvokeCommandAction MVVM 传递参数
【发布时间】:2015-07-16 13:39:01
【问题描述】:

我想根据某些业务逻辑禁用单元格/列。我正在使用ShowingEditor 事件和ShowingEditorEventArgs 来取消它。传递ShowingEditorEventArgs 会非常好。我可以将整个网格作为参数传递。使用下面的代码。但我只想传递选定单元格的ShowingEditorEventArgs。可能是一些相关的资源绑定帮助我在这里。

<dxg:GridControl x:Name="grid" >
                <dxg:GridControl.View>
                    <dxg:TableView Name="view"  ShowingEditor="view_ShowingEditor">
                    <i:Interaction.Triggers>

                        <i:EventTrigger EventName="ShowingEditor">
                            <i:InvokeCommandAction Command="{Binding ShowingEditorCommand}" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType={x:Type dxg:GridControl}}}" />

... 注意:

  1. 我无法使用 MVVM 灯(GalaSoft)。
  2. 交互没有给我 CallMethodAction。

    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
    <ei:CallMethodAction
    
  3. 我不想传递ViewModel的绑定属性(例如SelectedItem

  4. 使用 DevExpress GridControl

【问题讨论】:

    标签: wpf mvvm devexpress-wpf


    【解决方案1】:

    考虑使用 DevExpress MVVM 框架,您可以在其中将事件 args 作为参数传递给视图模型:

    <dxmvvm:Interaction.Behaviors>
        <dxmvvm:EventToCommand EventName="ShowingEditor" Command="{Binding ShowingEditorCommand}" PassEventArgsToCommand="True" />
    </dxmvvm:Interaction.Behaviors>
    

    甚至在将 EventArgs 对象传递给您的命令之前,使用 EventArgsConverter 属性指定的转换器进行转换。

    查看EventToCommand 文章以了解更多信息。

    附:如果您由于某种原因无法使用 DevExpress MVVM 框架,this post 描述了如何实现自定义 TriggerAction,手动将事件参数传递给命令。

    【讨论】:

      猜你喜欢
      • 2021-06-02
      • 1970-01-01
      • 2017-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-13
      • 2014-12-19
      • 2023-03-19
      相关资源
      最近更新 更多