I am finally biting the bullet and learning something about WPF. I have Visual Studio 2008 and Expression Blend installed and I am off to the races. I have been doing Windows programming since Windows 3.0 and followed the evolution of UI development using MFC, VB, and WinForms. WPF is very cool. I read this by David Chappell when I first got started with WPF. It is a good read.
So, last night I was working away on one of my prototype projects and I needed to pop a dialog to collection some information from the user. Well, this is my first time popping a dialog in WPF and I encountered several differences between WinForms and WPF dialogs.
I have a control hosted in a Window. The control is responsible for popping the dialog to gather additional information. I would like the dialog to pop centered over the parent window. I would like to know if the user chose to cancel the dialog or not. Here is the source:
A few things to notice:
- I set the owner by calling a static method on the Window class called GetWindow. I pass the control's parent to method, which in turn returns the Window object associated with Parent's FrameworkElement
- I call ShowDialog, but unlike WinForms, I don't collect the DialogResult as a return value
- DialogResult is a bool? type, so if it is null or is set to false, I know that the user canceled the dialog.
Very different from WinForms, but that's the point!