wpf - 使用 InvokeCommandAction MVVM 传递参数

标签 wpf mvvm devexpress-wpf

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

<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}}}" />

...
笔记:
  • 我无法使用 MVVM灯 (GalaSoft)。
  • 交互没有给我 CallMethodAction。
    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
    <ei:CallMethodAction
    
  • 我不想传递 ViewModel 的绑定(bind)属性(例如 SelectedItem )
  • 使用 开发 express 网格控制
  • 最佳答案

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

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

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

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

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

    关于wpf - 使用 InvokeCommandAction MVVM 传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31455857/

    相关文章:

    c# - 无效操作异常 : This freezable cannot be frozen

    c# - slider ValueChanged 方法命令 (MVVM WPF Devexpress)

    c# - 如何对具有多个子层的根 ViewModel 进行单元测试?

    wpf - 使用 scrollviewer 截取 WPF datagrid 的屏幕截图

    c# - Visual Studio 中缺少 Nuget 包

    c# - Silverlight/WPF : I Don't Want ICommand to Change Button's IsEnabled Property, 这可能吗?

    devexpress-wpf - 如何在GridControl中显示所有继承的接口(interface)

    xaml - 在 XAML 底部显示 DevExpress DXTabControl 选项卡

    WPF - Task.Run(() => window.ShowDialog) 失败

    wpf - Button.WPF MVVM中的属性的选定类型吗?