C# 如何在Windows Phone 8.1中显示全屏模式内容对话框

C# 如何在Windows Phone 8.1中显示全屏模式内容对话框,c#,windows-phone-8.1,win-universal-app,C#,Windows Phone 8.1,Win Universal App,当用户尝试登录到我的应用程序时,我会显示一个包含一些文本块和进度条的ContentDialog 我选择ContentDialog是因为它是模态的,会阻止用户,直到应用程序收集所需信息并准备导航到下一页 以下显示适用于Windows Phone 8.1(通用应用程序)的内容对话框类 下面的代码显示了我为显示ContentDialog而编写的代码(我暂时将其放入OnNavigatedTo中进行测试,稍后将其移动到相应的通知功能) 这显示为 上面你可以看到它只覆盖了部分背景 我希望它显示为 通过使全

当用户尝试登录到我的应用程序时,我会显示一个包含一些文本块和进度条的ContentDialog

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

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

下面的代码显示了我为显示ContentDialog而编写的代码(我暂时将其放入OnNavigatedTo中进行测试,稍后将其移动到相应的通知功能)

这显示为 上面你可以看到它只覆盖了部分背景

我希望它显示为

通过使全屏模式

我曾尝试更改高度和其他属性,但无法使其正常工作


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

例如,您可以将网格作为
内容对话框的内容,并将其高度/宽度设置为当前窗口或布局网格的边界:

// 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();

您也可以考虑使用。

我找到了一种解决方案,可以消除代码落后。不确定这是否更像是一项工作。但它允许我轻松地使用绑定来决定何时显示此模式对话框以及何时隐藏它

这是我的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=“1”的网格的可见性,并决定何时显示模式窗口。

在Windows Phone 8.1中,ContentDialog具有
FullSizeDesired
布尔属性,当设置为true时,将以全尺寸模式打开对话框。()。如果需要,您需要将背景设置为透明颜色值

弹出窗口不是一个选项,因为它不是模态的。您上面给出的解决方案非常有效。谢谢但我使用的是MVVM模式,它几乎不鼓励任何代码落后。你能想出什么办法把它从代码中去掉吗?下面我有一个anser,它使用Canvas.ZIndex并处理可见性。但我不确定这是否更像是一种变通方法,而不是正确的方法。mvvm模式不是“无代码隐藏”模式。在这种模式下,你的应用程序逻辑不应该知道你的界面。那完全不同。是的,您应该避免代码隐藏,以使您的xaml尽可能具有最高的可维护性,但是如果代码隐藏可以解决您的问题,那么毫不犹豫地使用UIElements的可见性也是一个很好的解决方案。只记得处理手机的BackKey,因此它不是自动处理的。只是一句话:别忘了将'IsIndeterminate'绑定到可见性。如果可见性将被折叠,但IsIndeterminate仍为真,则它仍将在后台运行。
<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>