如何在Windows Phone 8.1中显示全屏Modal ContentDialog

当用户尝试登录我的应用程序时,我正在显示包含一些TextBlocks和ProgressBar的ContentDialog。

我选择ContentDialog是因为它是模态的并阻止用户,直到应用程序收集所需信息并准备导航到下一页。

以下链接显示可用于Windows Phone 8.1(通用应用程序)的内容对话框类。

下面的代码显示了我编写的用于显示ContentDialog的代码隐藏(我暂时将其放在OnNavigatedTo中进行测试,稍后将其移至适当的通知function)

//Progress Bar ProgressBar bar = new ProgressBar(); bar.IsIndeterminate = true; //Downloading Data text TextBlock txt = new TextBlock(); txt.Text = "Downloading data..."; txt.FontSize = 17; txt.Foreground = new SolidColorBrush(Colors.White); txt.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center; //This could take a few seconds TextBlock txt2 = new TextBlock(); txt2.Text = "This could take a few seconds."; txt2.FontSize = 17; txt2.Foreground = new SolidColorBrush(Colors.White); txt2.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center; //Please do not close the application. TextBlock txt3 = new TextBlock(); txt3.Text = "Please do not close the application."; txt3.FontSize = 17; txt3.Foreground = new SolidColorBrush(Colors.White); txt3.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center; StackPanel stk = new StackPanel(); stk.Children.Add(bar); stk.Children.Add(txt); stk.Children.Add(txt2); stk.Children.Add(txt3); ContentDialog dlg = new ContentDialog(); dlg.Content = stk; SolidColorBrush color = new SolidColorBrush(Colors.Black); color.Opacity = 0.7; dlg.Background = color; dlg.Margin = new Thickness(0, 250, 0, 0); dlg.ShowAsync(); 

这显示为 在此处输入图像描述 在上面你可以看到它只覆盖部分背景

我希望它显示为 在此处输入图像描述

通过制作全屏模式。

我试过改变高度和其他属性,但无法让它工作。

如果有人能指出我正确的方向,我会很高兴的。

我找到了一个消除背后代码的解决方案。 不确定这是否更像是一种解决方法。 但它允许我轻松使用Binding来决定何时显示此modal dialog以及何时隐藏它。

这是我的XAML

                   

我使用Binding来讨论具有Canvas.ZIndex =“1”的Grid的可见性,并决定何时显示模态窗口。

例如,您可以将Grid作为ContentDialog的内容,并将其高度/宽度设置为当前窗口的边界或LayoutGrid:

 // your code stk.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Center; Grid contentGrid = new Grid(); contentGrid.Height = Window.Current.Bounds.Height; contentGrid.Width = Window.Current.Bounds.Width; // or from LayoutGrid //contentGrid.Height = LayoutRoot.ActualHeight; //contentGrid.Width = LayoutRoot.ActualWidth; contentGrid.Width -= 40; // it seems that ContentDialog has some defaul margin contentGrid.Children.Add(stk); ContentDialog dlg = new ContentDialog(); dlg.Content = contentGrid; SolidColorBrush color = new SolidColorBrush(Colors.Black); color.Opacity = 0.7; dlg.Background = color; await dlg.ShowAsync(); 

您还可以考虑使用PopUp 。

在Windows Phone 8.1中,ContentDialog具有FullSizeDesired布尔属性,当设置为true时,将以完整大小模式打开对话框。 ( MSDN链接 )。如果需要,您需要将Background设置为透明颜色值。