locked
Nested Message dialogues - Access denied exception

    Question

  • Hi,

    My code goes like this:

    dialog.Commands.Add(new UICommand("Delete", async p =>
    {
           var messagedialog = new MessageDialog("UnabletoDelete");
           await messagedialog.ShowAsync();
    }));

    dialog.Commands.Add("Cancel", async p => Cancel()));
    await dialog.ShowAsync();

    which throws UnauthorizedAccessException. Please help me with this issue to get it resolved

    Friday, June 13, 2014 10:48 AM

Answers

  • use this approach:

    var dialog = new MessageDialog("wuiohweoiho");
    
                var deleteCommand = new UICommand("Delete");
    
                dialog.Commands.Add(deleteCommand);
                dialog.Commands.Add(new UICommand("Cancel"));
                if (deleteCommand == await dialog.ShowAsync())
                {
                    var messagedialog = new MessageDialog("UnabletoDelete");
                    await messagedialog.ShowAsync();
                }


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Friday, June 13, 2014 2:22 PM
  • You identified the basic problem: you can nest message dialogues. You must let the first one dismiss before showing the second. That said, repeating message dialogs is a really unfriendly UI. The first question you should always ask yourself before using a message box is "is there a better, non-modal way to present this information?" Only use the message box if there really isn't a better way. Since a failed delete shouldn't block usage of the entire app a modal block is overkill. Putting the message inlineor in a fly out would be much friendlier.

    See http://msdn.microsoft.com/en-us/library/windows/apps/xaml/Hh465330(v=win.10).aspx#errors and the Guidelines for message dialogues

    Friday, June 13, 2014 2:24 PM
    Owner

All replies

  • use this approach:

    var dialog = new MessageDialog("wuiohweoiho");
    
                var deleteCommand = new UICommand("Delete");
    
                dialog.Commands.Add(deleteCommand);
                dialog.Commands.Add(new UICommand("Cancel"));
                if (deleteCommand == await dialog.ShowAsync())
                {
                    var messagedialog = new MessageDialog("UnabletoDelete");
                    await messagedialog.ShowAsync();
                }


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Friday, June 13, 2014 2:22 PM
  • You identified the basic problem: you can nest message dialogues. You must let the first one dismiss before showing the second. That said, repeating message dialogs is a really unfriendly UI. The first question you should always ask yourself before using a message box is "is there a better, non-modal way to present this information?" Only use the message box if there really isn't a better way. Since a failed delete shouldn't block usage of the entire app a modal block is overkill. Putting the message inlineor in a fly out would be much friendlier.

    See http://msdn.microsoft.com/en-us/library/windows/apps/xaml/Hh465330(v=win.10).aspx#errors and the Guidelines for message dialogues

    Friday, June 13, 2014 2:24 PM
    Owner
  • Thanks a lot Dave, it worked :)
    Monday, June 16, 2014 1:02 PM
  • Note that while Dave's code may work, it's really not a friendly UI. Your users will thank you for redesigning it.
    Monday, June 16, 2014 2:36 PM
    Owner
  • Thanks for the suggestion Rob. Went through the link you posted. I will have to go through my code once again to check if redesigning is required.
    Tuesday, June 17, 2014 10:21 AM