在UWP应用中,当我在按钮单击事件中使用时,如下面的代码所示,我可以打开MessageDialog:
private async void TestBtn_Click(object sender, RoutedEventArgs e)
{
// Create a MessageDialog
var dialog = new MessageDialog("This is my content", "Title");
// If you want to add custom buttons
dialog.Commands.Add(new UICommand("Click me!", delegate (IUICommand command)
{
// Your command action here
}));
// Show dialog and save result
var result = await dialog.ShowAsync();
}
但是当我尝试在for循环中调用同一事件处理程序时,我的应用程序看不到任何内容。
for (int i = 0; i < 10; i++)
{
TestBtn_Click(null, null);
}
我希望应用程序暂停,并显示一些数据,如Console.ReadLine()一样。
答案 0 :(得分:1)
将返回类型从 void 更改为任务,这将使消息对话框处于等待状态。
let o = {a: 1,b: {c: {d: 2},e: 3}}
let map = {
'a': 'aaa',
'b': 'bbb',
'b.c.d': 'bcd'
}
function makeObj(obj, map, p=[]) {
let ret = {}
Object.entries(obj).forEach(([k, v]) => {
let path = p.concat(k) // add onto current path
let mapKey = map[path.join('.')] || k
ret[mapKey] = (typeof v === 'object')
? makeObj(v, map, path) // if an object recurse and pass on the current path
: v // otherwise set the value
})
return ret
}
console.log(makeObj(o, map))