Hel*_*ers 12 c# windows-phone-8.1 win-universal-app
当用户尝试登录我的应用程序时,我正在显示包含一些TextBlocks和ProgressBar的ContentDialog.
我选择ContentDialog是因为它是模态的并阻止用户,直到应用程序收集所需信息并准备导航到下一页.
以下链接显示可用于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();
Run Code Online (Sandbox Code Playgroud)
这显示为
在上面你可以看到它只覆盖部分背景
我希望它显示为

通过制作全屏模式.
我试过改变高度和其他属性,但无法让它工作.
如果有人能指出我正确的方向,我会很高兴.
Hel*_*ers 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>
Run Code Online (Sandbox Code Playgroud)
我使用Binding来讨论具有Canvas.ZIndex ="1"的Grid的可见性,并决定何时显示模态窗口.
Rom*_*asz 12
例如,你可以把电网作为你的内容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();
Run Code Online (Sandbox Code Playgroud)
您还可以考虑使用PopUp.
| 归档时间: |
|
| 查看次数: |
18729 次 |
| 最近记录: |