繁体   English   中英

弹出一个带有返回值的消息对话框

[英]popup a message dialog with return value

我是 c# 和 uwp 的新手

我弹出消息对话框的代码是

    private void messageBoxClick(IUICommand command)
    {
        // Display message showing the label of the command that was invoked
        //rootPage.NotifyUser("The '" + command.Label + "' command has been selected.", NotifyType.StatusMessage);
    }

    public async Task messageBoxShow(string s, string commandString1, string commandString2)
    {
        var dialog = new Windows.UI.Popups.MessageDialog(s);
        dialog.Commands.Add(new UICommand(commandString1, new UICommandInvokedHandler(this.messageBoxClick)));
        dialog.Commands.Add(new UICommand(commandString2, new UICommandInvokedHandler(this.messageBoxClick)));

        await dialog.ShowAsync();


    }

有用! 但我希望得到的风格是

    string s = messageBoxShow(s, commandString1, commandString2);

以前的样式可以改成这个样式吗

欢迎您的评论

MessageDialog的显示是一个异步操作, ShowAsync返回的结果是IUICommand 如果你想获取的字符串值是IUICommand.Label ,你可以这样写:

public async Task<string> messageBoxShow(string s, string commandString1, string commandString2)
{
    var dialog = new MessageDialog(s);
    dialog.Commands.Add(new UICommand(commandString1, new UICommandInvokedHandler(this.messageBoxClick)));
    dialog.Commands.Add(new UICommand(commandString2, new UICommandInvokedHandler(this.messageBoxClick)));
    var result = await dialog.ShowAsync();
    return result.Label;
}

用法

string label = await messageBoxShow(s, commandString1, commandString2);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM