【问题标题】:Bind DataGrid's PreviewDrop to a command property将 DataGrid 的 PreviewDrop 绑定到命令属性
【发布时间】:2013-09-03 12:31:37
【问题描述】:

我的 UI 中有 2 个列出车辆的数据网格。两个 DataGrid 完全相同,只是它们维护 2 个不同的 ObservableCollections。

我创建了一个 VehicleListViewModel,它包含一个 ObservableCollection 属性和不同的 ICommand 属性。所以我将 DataGrid1 的 DataContext 设置为 VehicleListViewModel (ViewModel1) 的第一个实例,将第二个 DataGrid 的 DataContenxt 设置为第二个实例 (ViewModel2)。

现在,我需要为两个数据网格实现 PreviewDrop。我也希望在 ViewModel 中包含此代码,而不是在代码隐藏中。但是,设置 PreviewDrop="xxxxxx" 仅允许在代码隐藏中定义事件处理程序。有谁知道这样做的方法吗?

【问题讨论】:

    标签: wpf events datagrid command


    【解决方案1】:

    EventToCommand 行为: EventToCommand

    将它放在您的数据网格上并将其绑定到您的视图模型中的命令属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-23
      • 1970-01-01
      • 2011-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多