ContentDialog Windows 10 Mobile XAML - 全屏 - 填充

3

我在我的项目中放置了一个ContentDialog,用于在Windows 10上使用登录弹出窗口。

当我在移动设备上运行此项目时,ContentDialog没有全屏显示,并且在此元素周围有最小的填充。键盘可见(例如在焦点元素文本框上),键盘和内容对话框之间存在边距。

有没有解决方案可以使其全屏显示?我将属性“FullSizeDesired”设置为true,但问题仍然存在?

有人帮忙去除这些:- 填充,- 全屏

我的代码如下:

<ContentDialog
    x:Class="ExampleApp.SignInContentDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ExampleApp"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Title="SIGN IN">

    <Grid x:Name="GridMobile" VerticalAlignment="Center" HorizontalAlignment="Center">

            <Button x:Name="MakeOff" 
            Height="32" BorderThickness="1" 
            HorizontalAlignment="Center"
            Foreground="Red" Background="Black"
            Style="{StaticResource ButtonStyle}"
            Margin="0">

            <HyperlinkButton x:Name="btnRegister"
            Height="32" BorderThickness="1" 
            HorizontalAlignment="Center"
            Foreground="Red" Background="Black"
            Margin="0"
            NavigateUri="www.google.pt"
            Style="{StaticResource HyperLinkButtonStyleMobile}"
            Content="Register">
                <HyperlinkButton.ContentTemplate>
                    <DataTemplate>
                    <TextBlock Text="{Binding}" />
                    </DataTemplate>
                </HyperlinkButton.ContentTemplate>
            </HyperlinkButton>
    </Grid>

页面底部的空白边距是为“PrimaryButton”和“SecondaryButton”保留的,但我需要更多的按钮,这个空白边距对我来说不合适。我想要移除它。
谢谢。

你能展示一下你自定义的 ContentDialog 的 XAML 吗? - Justin XL
抱歉,我不能在这里发布图片。你能否提供你的Skype ID或其他联系方式,以便我们就此进行沟通?我正在编辑这篇文章!谢谢。 - fipcurren88
你为什么不能在这里发布你的代码呢? - Justin XL
我现在发布了!请检查这个! - fipcurren88
1个回答

7
你看到间隙的原因不是因为任何特定的填充值,而是因为在ContentDialog的默认样式中,高度和宽度设置为Auto,这意味着你的内容只会被赋予所需的大小。
因此,要使内容拉伸以适应其父级,你只需要通过应用的自定义默认样式并将其放置在App.xaml中来覆盖默认样式。
<Style TargetType="local:SignInContentDialog">
    <Setter Property="Foreground" Value="{ThemeResource SystemControlPageTextBaseHighBrush}" />
    <Setter Property="Background" Value="{ThemeResource SystemControlBackgroundChromeMediumLowBrush}" />
    <Setter Property="HorizontalAlignment" Value="Center" />
    <Setter Property="VerticalAlignment" Value="Top" />
    <Setter Property="IsTabStop" Value="False" />
    <Setter Property="MaxHeight" Value="{ThemeResource ContentDialogMaxHeight}" />
    <Setter Property="MinHeight" Value="{ThemeResource ContentDialogMinHeight}" />
    <Setter Property="MaxWidth" Value="{ThemeResource ContentDialogMaxWidth}" />
    <Setter Property="MinWidth" Value="{ThemeResource ContentDialogMinWidth}" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:SignInContentDialog">
                <Border x:Name="Container">
                    <Grid x:Name="LayoutRoot">                                                     
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <!-- COMMENT OUT THESE FOLLOWING LINES -->

                        <!--<Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>-->
                        <Border x:Name="BackgroundElement" Background="{TemplateBinding Background}" FlowDirection="{TemplateBinding FlowDirection}" MaxWidth="{TemplateBinding MaxWidth}" MaxHeight="{TemplateBinding MaxHeight}" MinWidth="{TemplateBinding MinWidth}" MinHeight="{TemplateBinding MinHeight}">
                            <Grid x:Name="DialogSpace" VerticalAlignment="Stretch">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled" ZoomMode="Disabled" Margin="{ThemeResource ContentDialogContentScrollViewerMargin}" IsTabStop="False">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto" />
                                            <RowDefinition Height="Auto" />
                                        </Grid.RowDefinitions>
                                        <ContentControl x:Name="Title" Margin="{ThemeResource ContentDialogTitleMargin}" Content="{TemplateBinding Title}" ContentTemplate="{TemplateBinding TitleTemplate}" FontSize="20" FontFamily="Segoe UI" FontWeight="Normal" Foreground="{TemplateBinding Foreground}" HorizontalAlignment="Left" VerticalAlignment="Top" IsTabStop="False" MaxHeight="{ThemeResource ContentDialogTitleMaxHeight}">
                                            <ContentControl.Template>
                                                <ControlTemplate TargetType="ContentControl">
                                                    <ContentPresenter Content="{TemplateBinding Content}" MaxLines="2" TextWrapping="Wrap" ContentTemplate="{TemplateBinding ContentTemplate}" Margin="{TemplateBinding Padding}" ContentTransitions="{TemplateBinding ContentTransitions}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                                                </ControlTemplate>
                                            </ContentControl.Template>
                                        </ContentControl>
                                        <ContentPresenter x:Name="Content" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" FontSize="{ThemeResource ControlContentThemeFontSize}" FontFamily="{ThemeResource ContentControlThemeFontFamily}" Margin="{ThemeResource ContentDialogContentMargin}" Foreground="{TemplateBinding Foreground}" Grid.Row="1" TextWrapping="Wrap" />
                                    </Grid>
                                </ScrollViewer>
                                <Grid x:Name="CommandSpace" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Bottom">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition />
                                        <ColumnDefinition />
                                    </Grid.ColumnDefinitions>
                                    <Border x:Name="Button1Host" Margin="{ThemeResource ContentDialogButton1HostMargin}" MinWidth="{ThemeResource ContentDialogButtonMinWidth}" MaxWidth="{ThemeResource ContentDialogButtonMaxWidth}" Height="{ThemeResource ContentDialogButtonHeight}" HorizontalAlignment="Stretch" />
                                    <Border x:Name="Button2Host" Margin="{ThemeResource ContentDialogButton2HostMargin}" MinWidth="{ThemeResource ContentDialogButtonMinWidth}" MaxWidth="{ThemeResource ContentDialogButtonMaxWidth}" Height="{ThemeResource ContentDialogButtonHeight}" Grid.Column="1" HorizontalAlignment="Stretch" />
                                </Grid>
                            </Grid>
                        </Border>
                    </Grid>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

好的,但是我将这个样式复制到App.xaml中。 Visual Studio显示错误“未知目标类型'local:SignInContentDialog'”。 请帮我解决这个问题。 - fipcurren88
你需要在顶部定义命名空间 - xmlns:local="using:YourNamespaceName" - Justin XL
不... xmlns:local="using:ExampleApp - Justin XL
local:SignInContentDialog --> local:MyDialogSignIn; xmlns:local="using:ExampleApp --> xmlns:local="using:Windows10Programming.Client.Views. - Justin XL
这是一个系统行为,恐怕没有简单的解决方法。但是你可以尝试在 TextBox 获得焦点时(GotFocus),通过设置 this.Margin = new Thickness(0,-12,0,0); 给整个对话框一个负的顶部边距,并在调用 LostFocus 时将其设置回 0。 - Justin XL
显示剩余10条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接