UWP使用一个大按钮创建内容对话框

时间:2017-09-12 09:24:26

标签: c# uwp

我正在尝试创建一个内容对话框,中间只有一个按钮

我试图使用样式代码更改内容对话框的样式但没有任何改变iI仍然有两个按钮,如果我只使用一个按钮保持在左侧

这是我的代码

    <!-- Default style for Windows.UI.Xaml.Controls.ContentDialog -->
<Style TargetType="ContentDialog">
    <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="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="{ThemeResource SystemControlForegroundAccentBrush}"
                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 x:Name="ContentScrollViewer"
                    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="XamlAutoFontFamily"
                    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="Center" />
                                </Grid>
                            </Grid>
                        </Border>
                    </Grid>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

我已经更改了样式,我只有一个按钮调用Button1Host,但是当我创建一个内容对话框没有任何改变时,我试图使用<page.Resoures>将该代码复制到我的内容对话框xaml但是我得到了相同的值

希望你帮助我

2 个答案:

答案 0 :(得分:2)

找到CommandSpace网格,并将其第一列宽度设置为0

<Grid x:Name="CommandSpace"
      Grid.Row="1"
      HorizontalAlignment="Stretch"
      VerticalAlignment="Bottom">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="0" />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Border x:Name="Button1Host"
            Margin="{ThemeResource ContentDialogButton1HostMargin}"
            MinWidth="{ThemeResource ContentDialogButtonMinWidth}"
            MinHeight="{ThemeResource ContentDialogButtonMinHeight}" />
    <Border x:Name="Button2Host"
            Margin="{ThemeResource ContentDialogButton2HostMargin}"
            MinWidth="{ThemeResource ContentDialogButtonMinWidth}"
            MinHeight="{ThemeResource ContentDialogButtonMinHeight}"
            Grid.Column="1" />
</Grid>

答案 1 :(得分:1)

为什么不尝试使用内容模板,而不使用主要或辅助按钮。看看下面的代码:

<ContentDialog x:Name="contentD">
        <ContentDialog.ContentTemplate>
            <DataTemplate>
                <Grid Background="Pink">
                    <Button Content="My Lonely Button" VerticalAlignment="Bottom" HorizontalAlignment="Center" Margin="5"/>
                </Grid>
            </DataTemplate>
        </ContentDialog.ContentTemplate>
    </ContentDialog>