WPF DataGrid中的UpArrow/DownArrow键 [英] UpArrow/DownArrow keys in WPF DataGrid

查看:328
本文介绍了WPF DataGrid中的UpArrow/DownArrow键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对WPF的DataGrid中的UpArrow和DownArrow键有问题.

I have a problem with the UpArrow and DownArrow keys in WPF's DataGrid.

只要我在行上单击鼠标(因此会自动设置SelectedItem和SelectedIndex属性),然后按UpArrow/DwnArrow键,一切都很好:灯条根据这些键向上或向下移动.
如果我以编程方式将SelectedIndex或SelectedItem设置为另一行,则UpArrow/DownArrow键将显示以下奇怪行为:
DownArrow :下一次按键不会移动灯条,并且无论SelectedIndex为何,页面第一行的单元格周围都会出现一个粗体边框(有时在滚动某些行之后);第二个按键带来了光条 到页面的第二行.
UpArrow:(行为与上一个类似),第一次按键总是在页面最后一行的单元格周围显示一个粗体边框,而第二次按键会将灯条带到最后一行,但是一行. br/> 在这两种情况下,从第三次按键开始,该行为始终变得正常.

As long as I click the mouse on a row (thus automatically setting the SelectedItem and SelectedIndex properties) and then press UpArrow/DwnArrow keys everything's fine: the lightbar moves upwards or downwards according to the keys.
If I programmatically set the SelectedIndex or SelectedItem to a different row, then the UpArrow/DownArrow keys show this odd behaviour:
DownArrow: the first keypress doesn't move the lightbar and, regardless of the SelectedIndex, a bold border appears around a cell on the first row of the page (sometimes after some scrolling of the rows); the second keypress brings the lightbar to the second row of the page.
UpArrow: (behaviour similar to the previous one) the first keypress always shows a bold border around a cell on the last row of the page and the second keypress brings the lightbar to the last but one row.
In both cases the behaviour always becomes regular from the third keypress.

有人可以告诉我如何解决这个问题吗?
非常感谢!

Can anybody tell me how to solve this problem?
Thank you very much in advance!

推荐答案

我以前见过这种情况,令人沮丧.  有人会认为选择和项可以完成所需的工作(从代码中完成).这是您要引用的DataGrid还是列表框?你有什么可以放的代码 在skydrive上供我们下载和实验.

I've seen this behavior before and it is frustrating.  One would think that selecting and item would accomplish what is needed (from code).  Is this a DataGrid you are referring to or is it a Listbox?  Do you have any code you could put up on skydrive for us to download and experiment.

当WPF出现时,它改变了数据和GUI之间如何关联的概念.新的想法是,如SelectedItem中的数据选择现在控制着DataGrid.但是,当涉及到在数据网格中使用滚动条时,我认为这种行为是 由于WPF决定滚动我们的滚动条,有时会有点奇怪.

When WPF came out it changed the concept of how Data and GUI are related.  The new idea was that the data selection as in SelectedItem now controlled the DataGrid.  But when it comes to having a scrollbar in a datagrid I think the behavior is a bit odd at times due to WPF deciding to scroll our not.


这篇关于WPF DataGrid中的UpArrow/DownArrow键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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