-1

I am currently working on a Windows Presentation Foundation app and I need to make use of Message boxes. I want to get few information from user inside Message Box popup.

But they appear always like this: Example of a Messagebox I get.

But I think the actual look of it should be like that: Example of the style I would like  to get.

Does anybody know, why this is, and how to solve it? I tried all everything listed here , but nothing worked.

habib
  • 2,366
  • 5
  • 25
  • 41
ExampleWasTaken
  • 43
  • 1
  • 10

3 Answers3

0

MessageBox is very limited. Based on your screenshot, you should just create your own child Window with your own XAML so you can get the user input.

Keithernet
  • 2,349
  • 1
  • 10
  • 16
0

I agree with Keithernet, build your own. Its more of an Input Dialog box. You may want to plan it to create a window, create it with ex: 4 parameters which you could override so you can apply them in the form including

The title,
The prompt you want the user to fill in
optional default button 1 text
optional default button 2 text.

have the input value stored into a public property in the window for the text to be bound to during entry.

If the user clicks the cancel button (or similar), clear the text entry and close the window. If ok button, just close the window.

Then, when you call it with a YourWindow.ShowDialog(), upon return, you can look at the public property for that input text value.

You could even do with a property / flag if the user cancelled directly or not. I have done similar in a couple of my WPF apps.

DRapp
  • 47,638
  • 12
  • 72
  • 142
  • Sounds like a real good solution! But how can I make the Messagebox the only clickable one? If I try it like that, I can still click my base application. – ExampleWasTaken May 13 '20 at 04:10
  • @t-kldw, When you have a window, instead of calling YourWindow.Show(), do YourWindow.ShowDialog() which makes it MODAL meaning you must answer ME first before you are allowed to go any further or return back to who called the window to begin with. – DRapp May 13 '20 at 11:48
0

You can find sample service implementations/NuGets for this on GitHub. Here is one I've created sometime ago: https://github.com/Dirkster99/MsgBox

Just create your own is an oversimplifying statement in my opinion because this is usually a dialog that you want to show in different parts of the application. Therefore, you have to settle for a software design pattern (I chose a service implementation as suggested here).

Likewise, there are other design decisions that should be taken. I have for instance made sure that the API has a compatible subset of Show API calls with the standard .Net MessageBox to make its application as flexible as possible. I also settled for light and dark themes hoping this will make its application easy in any other theme...

user8276908
  • 1,051
  • 8
  • 20