在DataGrid(WPF)中的DataCell旁边显示一个新窗口 [英] Showing a new Window right next to a DataCell in DataGrid (WPF)

查看:114
本文介绍了在DataGrid(WPF)中的DataCell旁边显示一个新窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个场景,当用户单击WPF中DataGrid中的单元格时,我想打开它旁边的NumPad(这基本上是基于触摸的输入)。
我知道NumPad是一个单独的窗口。

I want a scenario when a user clicks on a cell in DataGrid in WPF, I want to open NumPad next to it (This is basically for touch based input). The NumPad, I understand is a separate window.

1)如何知道选择了哪个单元格
2)如何显示单元格旁边的NumPad?
3)如何找到要定位NumPad的单元格坐标?
4)如何根据NumPad条目设置单元格的值?

1) How can I know which Cell is selected
2) how can I show the NumPad next to the cell?
3) How can I find the coordinates of cell to position my NumPad?
4) How can I set the value of cell based on NumPad entry?

NumPad是同一应用程序中的WPF用户控件。
DataGrid是一个.NET 4控件。
这是一个普通的Windows桌面应用程序

NumPad is a WPF User Control in the same application. DataGrid is a .NET 4 Control. It's a normal Windows Desktop application

推荐答案

这不是一项琐碎的任务,您应该对WPF有所了解完成此操作,但是这里有一些想法您可能要寻找的内容:

This is not a trivial task and you should have some knowledge of WPF to accomplish this, but here are some ideas what you might look for:


  1. DataGridCell.IsSelected 属性会告诉您是否选择一个单元格。

  2. 我会使用 弹出窗口 ,以直接在单元格旁边显示NumPad。

  3. 如果使用弹出窗口,则不需要坐标,但是可以使用 Popup.Placement 属性。另请参见此MSDN文档:弹出窗口放置行为

  4. 您可以尝试使用从NumPad到DataGridCell中用户控件的绑定。

  1. The DataGridCell.IsSelected property tells you whether a cell is selected.
  2. I would use a Popup to show the NumPad directly besides the cell.
  3. If you use a Popup you do not need the coordinates, but you can specify the relative placement using the Popup.Placement property. Also see this MSDN document: Popup Placement Behavior
  4. You could try to use a Binding from the NumPad to the user control in the DataGridCell.

使用< a href = http://msdn.microsoft.com/zh-cn/library/system.windows.controls.datagrid.cellstyle.aspx rel = nofollow noreferrer> DataGrid.CellStyle DataGridColumn.CellStyle 属性,您可以为DataGrid的所有单元格或某些特定列指定替代样式。在这种样式中,您可以更改模板并添加 Popup ,只有在选择了当前单元格后才能打开该模板。您可以通过绑定 Popup.IsOpen 属性添加到 DataGridCell.IsSelected 属性。

Using the DataGrid.CellStyle or the DataGridColumn.CellStyle property you can specify an alternate style for all cells of the DataGrid or some specific column. Within this style, you could change the template and add a Popup which is opened only if the current cell is selected. You can easily achieve this by binding the Popup.IsOpen property to the DataGridCell.IsSelected property.

这只是一个初步的想法。您仍然必须查看提供的MSDN链接,并阅读有关WPF的其他内容。尽管学习这种 WPF方式(即仅XAML)可能要花一些时间,但(在我看来)比使用大量的代码隐藏来确定当前选定的单元格(将控件放置在正确的位置)要容易得多,将数据从NumPad传输到单元格,依此类推...

This is just an initial idea. You will still have to have a look at the provided MSDN links and also read some other stuff about WPF. Although it might take some time to learn this 'WPF way' (i.e. only XAML), it is (in my eyes) much easier than using lots of code-behind to determine the currently selected cell, positioning a control at the correct location, transferring the data from the NumPad to the cell and so on...

这篇关于在DataGrid(WPF)中的DataCell旁边显示一个新窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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