当用户尝试登录我的应用时,我正在显示包含一些TextBlocks和ProgressBar的ContentDialog。
我选择ContentDialog是因为它是模态的并阻止用户,直到应用程序收集所需信息并准备好导航到下一页。
以下link显示适用于Windows Phone 8.1(通用应用)的内容对话类。
以下代码显示我为编写ContentDialog而编写的代码隐藏(我暂时将其放入OnNavigatedTo进行测试,稍后将其移至适当的通知功能)
//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();
显示为
上面你可以看到它只涵盖了背景的一部分
我希望它显示为
制作全屏模式。
我尝试过更改高度和其他属性但无法使其正常工作。
如果有人能指出我正确的方向,我会很高兴。
答案 0 :(得分:17)
我找到了一个消除背后代码的解决方案。不确定这是否更像是一种解决方法。但它允许我轻松使用Binding来决定何时显示此模态对话框以及何时隐藏它。
这是我的XAML
<Grid>
<Grid Visibility="{Binding IsDownloadingData}" Canvas.ZIndex="1" Background="{StaticResource PartiallyTransparentBlackColor}" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ProgressBar Grid.Row="1" IsIndeterminate="True"/>
<TextBlock Grid.Row="2" Text="Downloading Data..." FontSize="17" Foreground="White" HorizontalAlignment="Center"/>
<TextBlock Grid.Row="3" Text="This could take a few seconds." FontSize="17" Foreground="White" HorizontalAlignment="Center"/>
<TextBlock Grid.Row="4" Text="Please do not close the application." FontSize="17" Foreground="White" HorizontalAlignment="Center"/>
</Grid>
<ScrollViewer Canvas.ZIndex="0" VerticalAlignment="Stretch" Margin="0,10,0,10">
<!-- The XAML that should be hidden goes here (In my case LOGIN PAGE XAML) -->
</ScrollViewer>
我玩弄了具有Canvas.ZIndex =&#34; 1&#34;的网格的可见性。使用Binding并决定何时显示模态窗口。
答案 1 :(得分:12)
例如,您可以将网格作为ContentDialog
的内容,并将其高度/宽度设置为当前窗口的 Bounds 或您的LayoutGrid:< / p>
// 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。
答案 2 :(得分:5)
在Windows Phone 8.1中,ContentDialog具有FullSizeDesired
布尔属性,当设置为true时,将以完整大小模式打开对话框。 (MSDN link)。如果需要,您需要将Background
设置为透明颜色值。