简体   繁体   English

WPF MoveFocus()在Vista而非XP上运行

[英]WPF MoveFocus() working on Vista, not XP

The following bit of code works on Vista as expected (focus is moved down the ListView), but on XP SP3 (with .Net 3.5 SP1 on both) it moves only between the first two items of the ListView. 下面的代码可以在Vista上正常工作(焦点移到ListView上),但是在XP SP3(两个都带有.Net 3.5 SP1)上,它仅在ListView的前两个项目之间移动。

if (myListView.SelectedItem != null) {
    IInputElement orig = FocusManager.GetFocusedElement(this);
    FocusManager.SetFocusedElement(this, myListView);
    ListViewItem lvi = myListView.ItemContainerGenerator.ContainerFromItem(myListView.SelectedItem) as ListViewItem;
    TraversalRequest down = new TraversalRequest(FocusNavigationDirection.Down);

    Boolean result = lvi.MoveFocus(down);
    Console.WriteLine(result.ToString());
    FocusManager.SetFocusedElement(this, orig);
}

I'm calling this code from the window's previewkeydown event, when the focus is in a textbox. 当焦点位于文本框中时,我从窗口的previewkeydown事件中调用此代码。 I'm digging into the framework now to try and find what is different between XP and Vista inside of MoveFocus(). 我现在正在研究该框架,以尝试在MoveFocus()中发现XP和Vista之间的区别。 I feel like I'm doing web development again, testing browsers for quirks... 我觉得我正在再次进行Web开发,正在测试浏览器的怪癖...

Did you run Windows XP Service Pack2, in the doc the requirements are : Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003 您是否运行过Windows XP Service Pack2,在文档中的要求是:Windows 7,Windows Vista,Windows XP SP2,Windows Server 2008 R2,Windows Server 2008,Windows Server 2003

Msdn doc MSD文件

For me, I develop WPF apps under XP and all is working right... 对我来说,我在XP下开发WPF应用程序,并且一切正常。

My feeling in general is that many features in WPF uses technology that is new in Vista, and not supported in XP. 我的总体感觉是,WPF中的许多功能都使用Vista中的新技术,而XP中不支持该技术。 Things I have experienced are mainly related to visual effects, but in your case, it is obviously something else. 我所经历的事情主要与视觉效果有关,但就您而言,这显然是另外一回事。

My initial thought in your case is that there are some windows messages that are new in Vista that does not work in XP. 在您的情况下,我最初的想法是,某些Windows消息是Vista中的新增功能,而这些消息在XP中不起作用。

XP SP2满足了VS2008的要求,WPF最适合Windows Vista / Windows 7,可能就是这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM