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);
}
No comments:
Post a Comment