在我的弹出窗口(包含游戏选项控件)中,我有“重置高分”按钮。按钮触发一个带有文本块“你确定...”和两个按钮“是”和“否”的MessageDialog 。但是,当 MessageDialog 打开时,Popup 会关闭。你知道如何让弹窗还活着吗?
问问题
677 次
2 回答
4
我能够使用Action
委托作为MessageDialog
关闭时的回调来解决这个问题。
关键是在函数中的await
on之后调用 Action 。MessageDialog
ShowAsync
async
另一个关键是关闭并打开您的弹出窗口以IsLightDismissEnabled
实际控制。
XAML:
<Popup
IsLightDismissEnabled="{Binding IsLightDismiss, Mode=TwoWay}"
IsOpen="{Binding IsPopupOpen, Mode=TwoWay}">
视图模型:
private bool isPopupOpen;
public bool IsPopupOpen
{
get { return this.isPopupOpen; }
set { this.SetProperty(ref this.isPopupOpen, value); }
}
private bool isLightDismiss;
public bool IsLightDismiss
{
get { return this.isLightDismiss; }
set { this.SetProperty(ref this.isLightDismiss, value); }
}
protected void ShowDialog()
{
this.IsLightDismiss = false;
this.IsPopupOpen = false;
this.IsPopupOpen = true;
Action showPopup = () => {
this.IsLightDismiss = true;
this.IsPopupOpen = false;
this.IsPopupOpen = true;
};
ShowMessageDialog("message", "title", showPopup);
}
private async void ShowMessageDialog(string message, string title, Action callback)
{
var _messageDialog = new MessageDialog(message, title);
await _messageDialog.ShowAsync();
callback();
}
于 2013-09-18T20:44:45.450 回答
1
设置你Popup
的IsLightDismissEnabled
属性false
来实现这一点。
popup.IsLightDismissEnabled = false;
于 2012-11-10T18:51:21.657 回答