I'm creating my first WPF application and I wanted to understand if there is some kind of best practice when mixing functionality from the System.Windows.Forms namespace.
我正在创建我的第一个WPF应用程序,我想了解在混合System.Windows.Forms命名空间的功能时是否存在某种最佳实践。
Basically I want to have a popup window that opens by default in the bottom right hand corner of the users monitor.
基本上我想在用户监视器的右下角默认打开一个弹出窗口。
I can't find a Screen.PrimaryScreen.Bounds equivalent in the WPF namespaces. The examples I have seen suggest referencing System.Windows.Forms in the WPF Application.
我在WPF命名空间中找不到与Screen.PrimaryScreen.Bounds等效的内容。我见过的示例建议在WPF应用程序中引用System.Windows.Forms。
Which led me to the question, is this bad practice?, considering this reference isn't included by default.
这引出了我的问题,这是不好的做法吗?考虑到默认情况下不包括此引用。
I'm going to reference the WPF required resource in my existing windows forms application so that I can use this new WPF Window.
我将在现有的Windows窗体应用程序中引用WPF所需的资源,以便我可以使用这个新的WPF窗口。
Is there anything wrong with this approach?
这种方法有什么问题吗?
EDIT: I have actually found a property that returns information of the primary screen without referencing Windows Forms. The property is SystemParameters.WorkArea, my question of mixing references does still stand though.
编辑:我实际上找到了一个属性,返回主屏幕的信息,而不引用Windows窗体。该属性是SystemParameters.WorkArea,我的混合引用的问题仍然有效。
2 个解决方案
#1
Also you should consider resources and performance overheads as your application will have to load assemblies for both Windows Forms and WPF. It was mentioned several times within MSDN forums that WPF/Winforms interopping takes quite a lot of CPU cycles...
此外,您应该考虑资源和性能开销,因为您的应用程序必须为Windows窗体和WPF加载程序集。在MSDN论坛中多次提到WPF / Winforms互操作需要相当多的CPU周期......
#2
I don't think that referencing WinForms, when needed, is bad. Since WPF is still a relatively new technology, it just doesn't have complete feature parity with WinForms yet. For example, to my knowledge none of the standard Windows dialogs (Open File, Save File, Browse for Folder, etc.) have been implemented in WPF yet. The only way to display these in a WPF application is to use the WinForms version, or use P/Invoke to display the Win32 versions yourself. I go with the WinForms version personally, since they already took the trouble of wrapping the Win32 API.
我不认为在需要时引用WinForms是不好的。由于WPF仍然是一项相对较新的技术,它还没有与WinForms完全兼容。例如,据我所知,WPF中尚未实现标准Windows对话框(打开文件,保存文件,浏览文件夹等)。在WPF应用程序中显示这些内容的唯一方法是使用WinForms版本,或使用P / Invoke自己显示Win32版本。我亲自使用WinForms版本,因为他们已经解决了包装Win32 API的麻烦。
My approach is to use WPF as much as possible, and only fallback to WinForms if WPF doesn't fill my needs. Hopefully over the next release or so of WPF this will become less and less necessary.
我的方法是尽可能多地使用WPF,如果WPF不能满足我的需求,只能回退到WinForms。希望在WPF的下一个版本中,这将变得越来越不必要了。
#1
Also you should consider resources and performance overheads as your application will have to load assemblies for both Windows Forms and WPF. It was mentioned several times within MSDN forums that WPF/Winforms interopping takes quite a lot of CPU cycles...
此外,您应该考虑资源和性能开销,因为您的应用程序必须为Windows窗体和WPF加载程序集。在MSDN论坛中多次提到WPF / Winforms互操作需要相当多的CPU周期......
#2
I don't think that referencing WinForms, when needed, is bad. Since WPF is still a relatively new technology, it just doesn't have complete feature parity with WinForms yet. For example, to my knowledge none of the standard Windows dialogs (Open File, Save File, Browse for Folder, etc.) have been implemented in WPF yet. The only way to display these in a WPF application is to use the WinForms version, or use P/Invoke to display the Win32 versions yourself. I go with the WinForms version personally, since they already took the trouble of wrapping the Win32 API.
我不认为在需要时引用WinForms是不好的。由于WPF仍然是一项相对较新的技术,它还没有与WinForms完全兼容。例如,据我所知,WPF中尚未实现标准Windows对话框(打开文件,保存文件,浏览文件夹等)。在WPF应用程序中显示这些内容的唯一方法是使用WinForms版本,或使用P / Invoke自己显示Win32版本。我亲自使用WinForms版本,因为他们已经解决了包装Win32 API的麻烦。
My approach is to use WPF as much as possible, and only fallback to WinForms if WPF doesn't fill my needs. Hopefully over the next release or so of WPF this will become less and less necessary.
我的方法是尽可能多地使用WPF,如果WPF不能满足我的需求,只能回退到WinForms。希望在WPF的下一个版本中,这将变得越来越不必要了。