更改MessageDialog内容或从MessageDialog处理程序Windows Store应用显示新内容 [英] change MessageDialog content or show new one from MessageDialog handler Windows Store app

查看:122
本文介绍了更改MessageDialog内容或从MessageDialog处理程序Windows Store应用显示新内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有MessageDialog对话框负责删除确认.

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();
}

当用户单击Delete时,DeleteItemHandler会调用数据库上的操作,但是如何通知用户操作不成功?

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

我试图创建新的MessageDialog,但是得到了win32 exception.

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?

推荐答案

根据 Windows Store App准则 MessagegDialog并不是确认删除的好方法.

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();
    }

然后轻轻地解决:)

    <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>

这篇关于更改MessageDialog内容或从MessageDialog处理程序Windows Store应用显示新内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆