c# - 弹出带有返回值的消息对话框
问题描述
我是 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);
推荐阅读
- c++ - 函数重定义:const参数
- javascript - 自 npm 更新以来,Webpack 未生成捆绑包
- c++ - 为什么文件名 VS 链接器处理错误?我怎样才能改变它?
- c++ - 将函数返回值分配给 const 引用是什么意思?
- react-native - 如何在 Vue native 上使用自定义字体?
- sql-server - 如何获取 SSRS 的两个时间列之间的时间差
- c++ - g++ 4.8.5 上的全局命名空间问题(可能不完整的 C++11 支持)
- metal - 在金属中的半透明对象内渲染不透明对象
- api - 对于通过 kubernetes Canary 部署的应用程序,来自浏览器和 CLI 的不同 API 响应
- angular - 如何在故事书中向角度组件添加类?