1

I am new in WPF C#.

I want to use a MessageDialog, but I can't instantiate it because I can't find its namespace reference.

Please note that I can use a MessageBox.

I take a screenshot here:

enter image description here

What should I look to solve the problem?


Update I tried to use a ModalWindow as suggested by some user who deleted his answer, but I have the same problem.

enter image description here

Community
  • 1
  • 1
shogitai
  • 1,823
  • 1
  • 23
  • 50
  • 2
    WPF and WinForms are different, you shouldn't be using stuff from the `System.Windows.Forms` namespace (and not even reference the library). WPF has its own MessageBox – Camilo Terevinto Apr 12 '18 at 10:35
  • 1
    Also, not sure what `MessageDialog` is supposed to be, but [it's not part of the .NET Framework](https://referencesource.microsoft.com/#q=messagedialog). Do you mean the UWP [`MessageDialog` class](https://learn.microsoft.com/en-us/uwp/api/windows.ui.popups.messagedialog)? – Camilo Terevinto Apr 12 '18 at 10:37
  • I see it from [here](https://code.msdn.microsoft.com/windowsapps/How-to-show-message-dialog-35468701). – shogitai Apr 12 '18 at 10:39
  • As was said in another palce, MessageDialog is from UWP. Wich while Similar to WPF, has a totally different target Framework. The closest equivalent to the WindowsForms MessageBox in WPF is MessageBox (https://msdn.microsoft.com/en-us/library/ms602949.aspx) – Christopher Apr 12 '18 at 10:41
  • Why not just use System.Windows.MessageBox.Show("..."); ? – James Harcourt Apr 12 '18 at 10:44
  • For the while I'm using MessageBox.Show("...", "...");. But I want something more beautiful. – shogitai Apr 12 '18 at 10:46
  • `System.Windows.MessageBox` is a call to the windows default message box however UWP is designed to run with out knowing what operating systems they are running on ie Windows, windowsPhone, XBox so they had to include a new multi platform message box this is the `MessageDialog` hence its only available on UWP – MikeT Apr 12 '18 at 10:53
  • you can build your own message window by calling the window with the `Window.ShowDialog()` but you will have to design it yourself – MikeT Apr 12 '18 at 10:59

1 Answers1

1

MessageDialog is a UWP class, so it is only available to Windows 10 Store applications. As far as I know it does not exist in WPF.
The namespace is Windows.UI.Popups.

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
CFreitas
  • 1,647
  • 20
  • 29
  • 1
    You are correct, it's not part of WPF, it's only available to UWP apps. Not sure why the OP is looking for that in WinForms – Camilo Terevinto Apr 12 '18 at 10:40
  • 1
    OK thanks. It was what I needed to understand. However, there was no need to downvote the question, I worked to try to be clear and understandable. – shogitai Apr 12 '18 at 10:43
  • @kitsune: Nobody had any idea what "MessageBox" even is. Nor why you looked for it in the Windows.Forms Namespace. – Christopher Apr 12 '18 at 10:48
  • 1
    @kitsune: You had a book-example of a XY Problem (https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) You had a problem X (Designs were not respected). Convinced yourself Y (MessageDialog) was the only solution. And thus never explained X – Christopher Apr 12 '18 at 10:50
  • If Windows.IU.Popups namespace is only there for UWP, how do I use something like this in WPF? – tolache Mar 15 '20 at 11:51