MessageDialog does not close

I am using the following code to display a message dialog in my application:

MessageDialog dialog = new MessageDialog(null,
                                         DialogFlags.Modal,
                                         MessageType.Error, 
                                         ButtonsType.Ok,
                                         "An error occured: " );
dialog.Run();

      

The problem is that the Ok button on the window does nothing .... The window disappears when I click the X button in the upper right corner.

Any ideas?

+2


source to share


2 answers


You need to call dialog.Destroy();

after your calldialog.Run();



+5


source


You can also hook up an event Response

to get notified when a button is clicked:



    var dialog = new MessageDialog (this,
                                    DialogFlags.Modal, 
                                    MessageType.Info, 
                                    ButtonsType.YesNo, 
                                    "The Hulk could totally take Super Man");
    dialog.Response += (object o, ResponseArgs args) => {
        if (args.ResponseId == ResponseType.Yes) {
            Console.WriteLine("Yes clicked");
        } else if (args.ResponseId == ResponseType.No) {
            Console.WriteLine("No clicked");
        } else if (args.ResponseId == ResponseType.DeleteEvent) {
            Console.WriteLine("Dialog closed without clicking a button");
        }
        dialog.Destroy();
    };

    dialog.Run();

      

+1


source







All Articles