如何在Windows Phone 8.1中按下主页键时阻止ContentDialog关闭

时间:2016-07-18 08:19:03

标签: windows-phone-8.1

  

Folowing是我的代码,我用它来防止在返回键时丢失   按下,但它也阻止了“是”和“否”按钮   内容对话框。可能是什么原因?**

  dialog = new ContentDialog()
                 {
                    Title = "One basta found",
                            //RequestedTheme = ElementTheme.Dark,
                            //FullSizeDesired = true,
                            MaxWidth = this.ActualWidth // Required for Mobile!
                        };

                        // Setup Content
                        var panel = new StackPanel();

                        panel.Children.Add(new TextBlock
                        {
                            Text = file.Name+" is found. Do you want to add it?",
                            TextWrapping = TextWrapping.Wrap,
                        });


                        dialog.Content = panel;                    
                        // Add Buttons
                        dialog.PrimaryButtonText = "Yes";
                        dialog.IsPrimaryButtonEnabled = true;

dialog.Closing += ContentDialog_Closing;
void ContentDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
            {            
                    args.Cancel = true;            
            }

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您希望在从主屏幕返回应用程序后打开内容对话框。 也许你应该尝试一些解决方法。在onNavigatedFrom保存信息,如果内容对话框打开,并在onNavigatedTo检查此并再次显示内容对话框。

不运行visual studio:

override OnNavigatedTo(...){
   if(this.contentDialogShouldBeOpen){
      OpenContentDialog();
   }
}

override OnNavigatedFrom(...){
   this.contentDialogShouldBeOpen = isContentDialogOpen;
}