change MessageDialog content or show new one from MessageDialog handler Windows Store app
Asked Answered
T

2

0

I have MessageDialog dialogue responsible for delete confirmation.

private async void ShowDialogClick(object sender, RoutedEventArgs e)
{
    MessageDialog md = new MessageDialog("Are your sure you want to delete this?");

    md.Commands.Add(new UICommand("Delete",
        new UICommandInvokedHandler(DeleteItemHandler)));
    md.Commands.Add(new UICommand("Cancel"));

    await md.ShowAsync();
}

When user clicks Delete, DeleteItemHandler invokes operation on database, but how can I inform user about unsuccessful operation?

I tried to create new MessageDialog, but I got win32 exception.

private async void DeleteItemHandler(IUICommand command)
{
    MessageDialog md = new MessageDialog("New content");

    String result = DbDeletation();

    if(result != "OK")
        await md.ShowAsync();
}

What is the best way to inform user about error?

Tegan answered 16/2, 2014 at 0:38 Comment(1)
The MSDN article for MessageDialog.ShowAsync() specifically warns about this. Only one dialog can be active at a time, the MessageDialog is still active when your DeleteItemHandler runs. So you can't display another one in that method. Consider using Dispatcher.BeginInvoke() to run that code later, after the dialog is closed.Ligament
T
0

According to Windows Store App guidelines MessagegDialog isn't good way to confirm delete.

When the app needs to confirm the user's intention for an action that the user has taken, a flyout is the appropriate surface. See Guidelines for flyouts.

Now I've cleaner code...

    private async void DeleteItem_Click(object sender, RoutedEventArgs e)
    {
        MessageDialog md = new MessageDialog("Error");

        String result = DbDeletation();

        if (result != "OK")
            await md.ShowAsync();
    }

And more gently solution :)

    <Button HorizontalAlignment="Center"
            VerticalAlignment="Center"
            Content="Show Dialog">
        <Button.Flyout>
            <Flyout>
                <StackPanel>
                    <TextBlock>Are your sure you want to delte this?</TextBlock>
                    <Button Click="DeleteItem_Click"
                            Content="Delete"
                            HorizontalAlignment="Right"/>
                </StackPanel>
            </Flyout>
        </Button.Flyout>
    </Button>
Tegan answered 16/2, 2014 at 1:43 Comment(0)
T
1

You can't customize MessageDialos and call them in a row, so, you have two ways:

  1. Build your own Popup control with commands and do not close popup until the operation will return the result. Show progress or something like that. If error will happen - show it right in popup window.

  2. Use MessageDialog and show progess and error messages(if any) in the place where you called MessageDialog (near the button Delete, for example).

The second method fits Windows Store App guidelines a bit more.

Transfix answered 16/2, 2014 at 0:52 Comment(1)
Thank you for guidelines, I have good answer (MessageDialog isn't good way to delete confirm.Tegan
T
0

According to Windows Store App guidelines MessagegDialog isn't good way to confirm delete.

When the app needs to confirm the user's intention for an action that the user has taken, a flyout is the appropriate surface. See Guidelines for flyouts.

Now I've cleaner code...

    private async void DeleteItem_Click(object sender, RoutedEventArgs e)
    {
        MessageDialog md = new MessageDialog("Error");

        String result = DbDeletation();

        if (result != "OK")
            await md.ShowAsync();
    }

And more gently solution :)

    <Button HorizontalAlignment="Center"
            VerticalAlignment="Center"
            Content="Show Dialog">
        <Button.Flyout>
            <Flyout>
                <StackPanel>
                    <TextBlock>Are your sure you want to delte this?</TextBlock>
                    <Button Click="DeleteItem_Click"
                            Content="Delete"
                            HorizontalAlignment="Right"/>
                </StackPanel>
            </Flyout>
        </Button.Flyout>
    </Button>
Tegan answered 16/2, 2014 at 1:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.