WPF 数据网格双击单元 MVVM 设计 [英] WPF Datagrid Double Click Cell MVVM Design

查看:26
本文介绍了WPF 数据网格双击单元 MVVM 设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含数据网格的 WPF 应用程序.它绑定到我的列表对象订单",如下所示.

I have a WPF application that contains a datagrid. It is bound to my List object "Orders" shown below.

public class OrderBlock
{
  public Settings setting;
  public List<Order> orders;
}
public class Order
{
  public int Amount;
  public string OrderID;
  public string OrderIDDup;
  public string Name;
  public string NameDup;
  public bool DupIDs;
  // and some string, int fields
}

由于我无法控制的原因,可能有多个 OrderID,因此 OrderIDDup 属性.我的数据网格默认只显示 OrderID 而不是 OrderIDDup.

For reasons out of my control it is possible that there can be more than one OrderID, hence the OrderIDDup property. My datagrid by default shows just the OrderID and not the OrderIDDup.

我想要做的是让用户能够点击单元格 ID 并加载另一个窗口以向他们显示另一个 ID 以及两个名称,并让他们选择应该使用哪个 ID.

What I would like to do is for the user to be able to click on the cell ID and for another window to load to show them the other ID as well as the two names and let them choose which ID should be used.

我一直在读到 WPF DataGrid 不支持双击单元格的这种功能.所以我有点迷茫,我应该如何开始解决这个问题.我可以看到的另一个问题是,当我尝试(作为操作词)使用 MVVM 设计时,这种事件将如何暴露给我的视图模型?

I have been reading that the WPF DataGrid doesn’t support this functionality of double clicking on a cell. So I am a bit lost as how i should start going about this issue. The other issue I can see is that as I am trying (being the operative word) to use a MVVM design how would this kind of event be exposed to my view model?

这也是显示此类信息的最佳方式.

Also is this the best way to go about showing such information.

任何帮助都会很棒,谢谢,米

Any help would be great, Thanks, M

推荐答案

您可以双击网格而不是双击单元格

Instead of double-clicking on the cell you may double-click on the grid

<DataGrid.InputBindings>
    <MouseBinding Gesture="LeftDoubleClick" 
    Command="{Binding Edit}" 
    CommandParameter="{Binding ElementName=UsersDataGrid, Path=SelectedItem}" />
</DataGrid.InputBindings>

在视图模型中

    public ICommand Edit { get; private set; }

 Edit = new RelayCommand(EditUser, x => _isAdmin);



 private static void EditUser(object usr)
    {
        if (!(usr is User))
            return;

        new UserEditorViewModel(usr as User);
    }

这篇关于WPF 数据网格双击单元 MVVM 设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆