在uwp中排队ContentDialog
可以对ContentDialog进行排队并在另一个关闭后显示它? 我用这个来找到ContentDialog在uwp中排队ContentDialog
var popups = VisualTreeHelper.GetOpenPopups(Window.Current);
int i = 0;
foreach (var item in popups)
{
if (item.Child is ContentDialog)
i++;
}
if (i == 0)
{
//show ContentDialog
}
else
// add to my listOfContentDialog
但如果我尝试打开更多ContentDialog的同时也抛出操作不当开始异常。
UPDATE 根据杰登谷 - MSFT我的工作代码
private List<string> testowa_lista = new List<string>();
private async void Komunikat_siatki(string v)
{
if(mozeWyskoczyc)
{
mozeWyskoczyc = false;
//my internal code to generate ContentDialog using v string
testowa_lista.Remove(v);
mozeWyskoczyc = true;
if (testowa_lista.Count > 0)
{
var i = testowa_lista.First();
Komunikat_siatki(i);
}
}
else
{
testowa_lista.Add(v);
}
}
只有一个ContentDialog可以同时显示。
如果一个ContentDialog
所示,我们无法向另一个ContentDialog
。当您在TextBox
的LostFocus
事件中添加ShowAsync
方法并使用“点击”按钮时,它将同时显示两个ContentDialog
。
您应该能够添加一个布尔字段保存到,如果可以证明的ContentDialog
状态。
例如:
private async void Text_LostFocus(object sender, RoutedEventArgs e)
{
if (dialogCanShow)
{
dialogCanShow = false;
var textBox= sender as TextBox;
var contentDialog = new ContentDialog();
contentDialog.Title = textBox.Name;
contentDialog.CloseButtonText = "Close";
await contentDialog.ShowAsync();
dialogCanShow = true;
}
}
当我们关闭ContentDialog
,光标会显示当前TextBox
。
部分是我想要的...它可以防止打开多个然后一个ContentDialog但不创建队列。 – kdn29
@ kdn29看看https://stackoverflow.com/questions/33018346/only-a-single-contentdialog-can-be-open-at-any-time-error-while-opening-anoth/47986634#47986634 –
你可以使用一个消息,而不是对话框。
await new MessageDialog("First").ShowAsync();
await new MessageDialog("Second").ShowAsync();
不,它不是我所需要的 – kdn29
您可以将它们存储在某些集合,然后向他们展示一个接一个:
List<ContentDialog> dialogs = new List<ContentDialog>()
{
contentDialog1,
contentDialog2,
contentDialog3
};
foreach (ContentDialog dialog in dialogs)
{
await dialog.ShowAsync();
}
既然你需要排队多个内容的对话框,你可以试试这个:
int count = 1; //count is used to simply to have dynamic content in the dialogs
private async void startCreatingDialog()
{
var result = await createDialog(count.ToString()).ShowAsync();
if (result == ContentDialogResult.Primary)
{
//create a new dialog based on user's input
count++;
startCreatingDialog();
}
}
private ContentDialog createDialog(string content)
{
ContentDialog contentDialog = new ContentDialog()
{
Content = content,
//clicking on the primarybutton will create the next ContentDialog
PrimaryButtonText = "Show another dialog",
SecondaryButtonText = "Cancel"
};
return contentDialog;
}
开始展示你需要调用startCreatingDialog()
和休息对话框队列将根据用户的选择来处理..
希望这可以帮助..
我可以知道你想排队多少个ContentDialog?我会尽力根据那个提供一个解决方案.. – Pratyay
ContentDialogs的数量是动态的(最多5) – kdn29
还有另一种方法描述在https://stackoverflow.com/questions/33018346/only-a-single-contentdialog-可以在任何时间打开任何时候打开 - 错误 - 开 - 另一个/ 47986634#47986634 –