在 DataGrid (WPF) 中的 DataCell 旁边显示一个新窗口
我想要一个场景,当用户单击 WPF 中 DataGrid 中的单元格时,我想打开它旁边的 NumPad(这基本上用于基于触摸的输入)。 据我所知,数字键盘是一个单独的窗口。
1) 我如何知道选择了哪个单元格
2) 如何在单元格旁边显示数字键盘?
3) 如何找到单元格的坐标来定位我的数字键盘?
4) 如何根据数字键盘输入设置单元格的值?
NumPad 是同一应用程序中的 WPF 用户控件。 DataGrid 是一个 .NET 4 控件。 这是一个普通的 Windows 桌面应用程序
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) 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 is a WPF User Control in the same application.
DataGrid is a .NET 4 Control.
It's a normal Windows Desktop application
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是一项简单的任务,您应该具备一定的 WPF 知识才能完成此任务,但您可能需要了解以下一些想法:
DataGridCell.IsSelected
属性告诉您是否选择了单元格。弹出窗口
直接在单元格旁边显示数字键盘。
Popup
,则不需要坐标,但您可以使用Popup.Placement
属性。另请参阅此 MSDN 文档: 弹出窗口放置行为使用
DataGrid.CellStyle
或
DataGridColumn.CellStyle
属性,您可以为 DataGrid 的所有单元格或某些特定列指定替代样式。在此样式中,您可以更改模板并添加仅在选择当前单元格时才打开的Popup
。您可以通过绑定 轻松实现此目的将Popup.IsOpen
属性设置为DataGridCell.IsSelected
属性。这只是一个初步的想法。您仍然需要查看提供的 MSDN 链接,并阅读一些有关 WPF 的其他内容。虽然学习这种“WPF 方式”(即仅 XAML)可能需要一些时间,但(在我看来)它比使用大量代码隐藏来确定当前选定的单元格、将控件定位在正确的位置要容易得多,将数据从数字键盘传输到单元格等等......
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:
DataGridCell.IsSelected
property tells you whether a cell is selected.Popup
to show the NumPad directly besides the cell.Popup
you do not need the coordinates, but you can specify the relative placement using thePopup.Placement
property. Also see this MSDN document: Popup Placement BehaviorUsing the
DataGrid.CellStyle
or theDataGridColumn.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 aPopup
which is opened only if the current cell is selected. You can easily achieve this by binding thePopup.IsOpen
property to theDataGridCell.IsSelected
property.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...
我真的很喜欢格霍的回答。
按照他的建议,除了在样式文本列上使用模板列之外,还生成了以下 XAML:
希望这有帮助!
I really like Gehho's answer.
Doing as he suggested, besides using the Template column over styling text columns, resulted in the following XAML:
Hope this helps!