删除主要和次要按钮在 ContentDialog 上的空间 [英] Remove space that the primary and secondary buttons are holding on a ContentDialog

查看:28
本文介绍了删除主要和次要按钮在 ContentDialog 上的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 ContentDialog,它是 UWP 应用程序的一部分,我不需要默认的 PrimaryButton 和 SecondaryButton.如果我不定义按钮,对话框底部会有厚厚的填充.请参阅随附的屏幕截图.有没有办法去掉空格?谢谢.

I am writing a ContentDialog which is a part of a UWP app, I don't need the default PrimaryButton and SecondaryButton. There will be a thick padding on the bottom of the dialog if I don't define the buttons. Please see the screen shot attached. Is there a way to remove the space? Thank you.

推荐答案

您可以为此对话框创建一个新样式,删除包含按钮空间的网格.打开文件file,搜索ContentDialog,复制你应用中的默认样式,给它一个x:Key并修改它:

You can create a new Style for this dialog removing the Grid which contains the button space. Open the file file, search for ContentDialog, copy the default style in your app, give it an x:Key and modify it:

<Style TargetType="ContentDialog" x:Key="NoButtonsContentDialogStyle">
    <Setter Property="Foreground" Value="{ThemeResource ContentDialogForeground}" />
    <Setter Property="Background" Value="{ThemeResource ContentDialogBackground}" />
    <Setter Property="BorderBrush" Value="{ThemeResource ContentDialogBorderBrush}" />
    <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="ContentDialog">
                <Border x:Name="Container">
                    <Grid x:Name="LayoutRoot">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Border x:Name="BackgroundElement"
                            Background="{TemplateBinding Background}"
                            FlowDirection="{TemplateBinding FlowDirection}"
                            BorderThickness="{ThemeResource ContentDialogBorderWidth}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            MaxWidth="{TemplateBinding MaxWidth}"
                            MaxHeight="{TemplateBinding MaxHeight}"
                            MinWidth="{TemplateBinding MinWidth}"
                            MinHeight="{TemplateBinding MinHeight}">
                            <Grid x:Name="DialogSpace" VerticalAlignment="Stretch" Padding="{ThemeResource ContentDialogPadding}">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <ScrollViewer x:Name="ContentScrollViewer"
                                    HorizontalScrollBarVisibility="Disabled"
                                    VerticalScrollBarVisibility="Disabled"
                                    ZoomMode="Disabled"
                                    Margin="{ThemeResource ContentDialogContentScrollViewerMargin}"
                                IsTabStop="False">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto" />
                                            <RowDefinition Height="*" />
                                        </Grid.RowDefinitions>
                                        <ContentControl x:Name="Title"
                                            Margin="{ThemeResource ContentDialogTitleMargin}"
                                            Content="{TemplateBinding Title}"
                                            ContentTemplate="{TemplateBinding TitleTemplate}"
                                            FontSize="20"
                                            FontFamily="XamlAutoFontFamily"
                                            FontWeight="Normal"
                                            Foreground="{TemplateBinding Foreground}"
                                            HorizontalAlignment="Left"
                                            VerticalAlignment="Top"
                                            IsTabStop="False">
                                            <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>
                                <!-- I've removed the button content here -->
                            </Grid>
                        </Border>
                    </Grid>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

添加此代码,例如到您全局加载的 App.xaml 或样式文件,并在创建 ContentDialog 时在代码中设置样式:

Add this code e.g. to your App.xaml or Styles file you load globally and when creating the ContentDialog set the Style in code:

ContentDialog dialog = new ContentDialog();
dialog.Style = Application.Current.Resources["NoButtonsContentDialogStyle"] as Style;

这篇关于删除主要和次要按钮在 ContentDialog 上的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆