tags:

views:

360

answers:

2

Hi, 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.

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.

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.

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.

A: 

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.

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.

Andy
WPF does have OpenFileDialog and SaveFileDialog. They are in Microsoft.Win32 namespace.
Danko Durbić
Wow, I didn't know that. Thanks for the tip. :)
Andy
A: 

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...

Denis Vuyka