Search code examples
c#wpfwinformsmessagebox

Avoiding ambiguity with MessageBox in WPF


I've run into this problem a lot lately. I often write programs using WPF/C# and want to use an OpenFileDialog or some other class requiring System.Windows.Forms. I also frequently use MessageBoxes (They become ambigious between the two libraries when Forms is added).

I add the reference, but (even with the shortcut) I have to use something like F.MessageBox.Show(). Is there a way to just temporarily use the System.Windows.Forms reference when I need or something else that will allow me to keep MessageBox.Show() intact?


Solution

  • Microsoft moved a lot of Windows dialogs to the Microsoft.Win32 namespace so you don't need to add a reference to all of System.Windows.Forms.