10 reasons to consider WPF for your next desktop application - Reason 8. Interop
This is the 8th post in the series 10 reasons to consider WPF for your next desktop application by Josh Twist, this part explores Interop in WPF.
You can view the other reasons in the series below:
- Reason 1 - Rich Content Model
- Reason 2 - Databinding
- Reason 3 - DataTemplates
- Reason 4 - Triggers
- Reason 5 - Styles
- Reason 6 - Layout
- Reason 7 - The ListView
Earlier I introduced a series of posts entitled 10 reasons to consider WPF for your next desktop application. If you haven't read the intro yet, better head on back and read it first.
Other titles I considered for this particular post were:
Reason 8. What!? no datagrid?
or
Reason 8. 1 reason why you should consider WPF for your existing desktop applications.
So let's get started.
What!? No datagrid?
It is a well-known fact that WPF doesn't ship with a built-in DataGrid. Actually, this fact is perhaps the most commonly cited reason that WPF is not suitable for Line Of Business applications. If you're a fan of the datagrid then there is no doubt that this could be a problem for you.
Personally, it wouldn't bother me in the slightest because I'm proud to state that I've never used a DataGrid in any of my Windows Forms applications. I think it's a pretty lazy way of building a UI and a usability sticking point.
So, ignoring my rant above (at your peril;), the omission of a DataGrid doesn't have to rule out WPF.
Thanks to the wonders of the WindowsFormsHost there's nothing to stop you hosting a DataGrid directly inside your WPF application (if you still think you need a DataGrid given the Awesome ListView Control provided in WPF, that is).
<Window x:Class="Reason8.Window1"
xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns:my="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
Title="Reason8" Height="350" Width="700" >
<DockPanel>
<my:WindowsFormsHost Name="_windowsFormsHost" >
<wf:DataGrid x:Name="_gridView" />
</my:WindowsFormsHost>
</DockPanel>
</Window>
Here's the glorious hosted DataGrid in all it's glory.
It's even bound to my collection of books...
_gridView.DataSource = _books;
Why not have a play with the ClickOnce Reason 8 Sample and see it for yourself.
Now is a good point to note that the DataGrid isn't the only omission from the WPF control. Others include:
- DateTimePicker
- MaskedTextBox
- MonthCalendar
- PropertyGrid
These are all useful controls, especially in forms-over-data Line-of-Business applications so you really do need to think carefully before jumping on the WPF express instead of Windows Forms. This reinforces my notes of caution in the introductory post to this series: 10 reasons to consider WPF for your next desktop application.
Of course, you could plug these wholes with third party controls or even write them yourself - but that's precious project time lost.
Does it work the other way around?
Yes, there's a reason I considered calling this post: "1 reason why you should consider WPF for your existing desktop applications": You can host WPF inside of Windows Forms using the ElementHost control:
... and a screenshot to prove it:
Enough interop options to shake at a monkey's armpit.
Originally posted by Josh Twist on 20th November 2007 here.
Comments
Anonymous
November 30, 2008
PingBack from http://blog.a-foton.ru/index.php/2008/12/01/10-reasons-to-consider-wpf-for-your-next-desktop-application-reason-8-interop/Anonymous
November 30, 2008
PingBack from http://blog.a-foton.ru/index.php/2008/12/01/10-reasons-to-consider-wpf-for-your-next-desktop-application-reason-8-interop/Anonymous
November 30, 2008
The comment has been removedAnonymous
December 09, 2008
This is the 9th post in the series 10 reasons to consider WPF for your next desktop application by JoshAnonymous
December 10, 2008
Matthew - We totally agree with your comments. Please note that the post was originally published over a year ago and totally predates the codeplex stuff. Josh is considering a '10 Reasons: 1 year on' post as an update his initial series so watch this space!