Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pause execution like a MessageBox or a Dialog

Tags:

c#

mvvm

wpf

I am creating an application that shows some alerts. With MessageBox.Show its ok, but its ugly for this project. Its a Metro like app, so we created a Metro-like MessageBox.

Our custom MessageBox is a grid that changes its visibility when we need it. The issue is that a real MessageBox, stops the execution util the user clicks its "ok".

So, how can I simulare this behavior?

like image 256
Ricardo Polo Jaramillo Avatar asked Dec 06 '25 14:12

Ricardo Polo Jaramillo


1 Answers

Make your custom messagebox a form. Then you can call customMessageBoxFormInstance.ShowDialog().. which blocks exactly the same as a messagebox would.

This is what you would do:

  • Create a form that resembles your custom MessageBox. Perhaps you can move your grid into it.
  • Put a button on there which has it's DialogResult property set to OK.
  • Use this wherever you want your alert to show up:

    if (customMessageBoxInstance.ShowDialog() == DialogResult.OK) {
        // they clicked okay..
    }
    

It will block exactly as you expect a MessageBox to do..

like image 145
Simon Whitehead Avatar answered Dec 08 '25 04:12

Simon Whitehead



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!