WPF关于WindowInteropHelper的一个BUG
来源:百度文库 编辑:神马文学网 时间:2024/05/23 19:30:04
在Windows SDK中关于WindowInteropHelper类的介绍中,关于其Owner属性的说明和实现有些问题。
原文是:An example scenario is if you need to host a WPF dialog box in a Win32 application. Initialize the WindowInteropHelper with a WPF window object for the dialog. You can then get the WPF window‘s handle (HWND) from the Handle property and specify the owner for the WPF window with the Owner property. The following code example shows how to use WindowInteropHelper when hosting a WPF dialog box in a Win32 application.
大意是通过WindowInteropHelper的Owner属性可以把WPF窗口的Owner属性设置为一个Win32的窗口句柄HWND。但是这个功能的实现是有问题的。有兴趣的朋友可以通过下面的代码进行测试:
Window myDialog = new Window();
myDialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;
WindowInteropHelper wih = new WindowInteropHelper(myDialog);
wih.Owner = ownerHwnd;
myDialog.ShowDialog();
这段代码最后显示的窗口不会位于Owner窗口的中心。事实上,WindowInteropHelper.Owner属性设置的是Window类的_ownerHandle成员。这个成员和Window.Owner设置的成员不是同一个。因此,文档中的说明和WPF的实际实现不相符的。这个问题基本已经确认是WPF的一个BUG。
原文是:An example scenario is if you need to host a WPF dialog box in a Win32 application. Initialize the WindowInteropHelper with a WPF window object for the dialog. You can then get the WPF window‘s handle (HWND) from the Handle property and specify the owner for the WPF window with the Owner property. The following code example shows how to use WindowInteropHelper when hosting a WPF dialog box in a Win32 application.
大意是通过WindowInteropHelper的Owner属性可以把WPF窗口的Owner属性设置为一个Win32的窗口句柄HWND。但是这个功能的实现是有问题的。有兴趣的朋友可以通过下面的代码进行测试:
Window myDialog = new Window();
myDialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;
WindowInteropHelper wih = new WindowInteropHelper(myDialog);
wih.Owner = ownerHwnd;
myDialog.ShowDialog();
这段代码最后显示的窗口不会位于Owner窗口的中心。事实上,WindowInteropHelper.Owner属性设置的是Window类的_ownerHandle成员。这个成员和Window.Owner设置的成员不是同一个。因此,文档中的说明和WPF的实际实现不相符的。这个问题基本已经确认是WPF的一个BUG。
WPF关于WindowInteropHelper的一个BUG
一个Bug 差点让服务器的文件系统崩溃
WPF分辨率的独立性
剖析层出不穷的BUG
WPF入门一:搭建WPF的开发环境
闲话WPF之十四(WPF的数据处理 [1] )
Windows 2003 X64中IIS 6应用程序池内存回收的一个Bug @阿良.NET
[翻译] 构建完美的WPF开发工作站
所有论坛都存在的BUG
编写优秀Bug报告的艺术
Bug管理的经验和实践
Bug管理的经验和实践
Bug管理的经验和实践
Bug管理的流程和几个重点
编写优秀Bug报告的艺术
Bug管理的经验和实践
Fortran编程BUG的都市传说
IE中伪类:hover的使用及BUG
Bug管理的经验和实践
WPF, WPF/E释疑
[转载]Bug管理的流程和几个重点以及Bug管理工具
为Tomcat写了一个增强的可以限制浏览器和防盗链过滤器提交到Tomcat的bug里被拒了:( - lizongbo 的编程学习
WPF,DirectUI,DirectX,MFC,WMF之间的关系
一个关于健康的文章