I thought writing the placeholder text box was much easier in WPF than WinForms, since WPF allows graphical elements to be overlaid easily. I was wrong! For WinForms, a P/Invoke can achieve that function since XP and Vista had it built-in. Thanks to Aaron for the source.
Showing posts with label Interop. Show all posts
Showing posts with label Interop. Show all posts
Sunday, May 17, 2009
Monday, June 18, 2007
WPF Interop with ExceptionMessageBox
Update: Apparently there is a better way to do it, as explained at IEnumerable<Stuff>
I've been porting part of a Windows Forms project to Windows Presentation Foundation. I've been using ExceptionMessageBox to show error messages. Its Show method takes an IWin32Window argument. However, WPF forms does not implement the IWin32Window, so there is no way to directly pass System.Windows.Window into the argument. To 'convert' a WPF Window into IWin32Window, I've used the following
For those who have not seen the gem called ExceptionMessageBox, visit
http://geekswithblogs.net/cicorias/archive/2006/05/09/77715.aspx and http://geekswithblogs.net/kobush/archive/2006/05/21/ExceptionMessageBox.aspx
I've been porting part of a Windows Forms project to Windows Presentation Foundation. I've been using ExceptionMessageBox to show error messages. Its Show method takes an IWin32Window argument. However, WPF forms does not implement the IWin32Window, so there is no way to directly pass System.Windows.Window into the argument. To 'convert' a WPF Window into IWin32Window, I've used the following
try
{
throw new Exception();
}
catch (Exception ex)
{
ExceptionMessageBox msgBox = new ExceptionMessageBox(
ex,
ExceptionMessageBoxButtons.OK,
ExceptionMessageBoxSymbol.Error,
ExceptionMessageBoxDefaultButton.Button1);
System.Windows.Interop.WindowInteropHelper windowInterop = new System.Windows.Interop.WindowInteropHelper(this);
System.Windows.Forms.Control winForm = System.Windows.Forms.Form.FromHandle(windowInterop.Handle);
msgBox.Show(winForm);
}
Subscribe to:
Posts (Atom)