如何解决弹出一个带有返回值的消息对话框
我是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);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。