XAML 内容对话框不滚动

aij0ehis  于 2023-02-27  发布在  其他
关注(0)|答案(4)|浏览(112)

在UWP中,ContentDialog只会调整到一定的大小,然后内容会被剪切-而不是滚动。如果我在内容中包含一个ScrollViewer,它只会随着内容的无限增长而永远不会滚动。

hsvhsicv

hsvhsicv1#

由于我在其他地方找不到这个问题的解决方案,下面是我的解决方案:
https://msdn.microsoft.com/en-us/library/windows/apps/mt299120.aspx复制ContentDialog的默认样式,并将ScrollViewer的属性从:

<ScrollViewer x:Name="ContentScrollViewer"
                    HorizontalScrollBarVisibility="Disabled"
                    VerticalScrollBarVisibility="Disabled"

<ScrollViewer x:Name="ContentScrollViewer"
                    HorizontalScrollBarVisibility="Auto"
                    VerticalScrollBarVisibility="Auto"

听起来很简单,但是我花了太多时间调试可视化树才弄明白这一点...
以下是应用于您希望可滚动的ContentDialog的完整样式:

<!-- Default style for Windows.UI.Xaml.Controls.ContentDialog -->
        <Style TargetType="ContentDialog" x:Key="ScrollableContentDialogStyle">
            <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="Auto"
                                                      VerticalScrollBarVisibility="Auto"
                                                      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>
mmvthczy

mmvthczy2#

不确定在最新的SDK中是否有一些相关的增强,但至少现在可以使用(在对话框中显示长文本的非常简单的方法,而不需要任何新的XAML):

async Task ShowDialogAsync(string title, string text)
{
    var dialog = new ContentDialog()
    {
        Title = title,
        Content = new ScrollViewer()
        {
            Content = new TextBlock() { Text = text },
        },
        CloseButtonText = "ok"
    };

    await dialog.ShowAsync();
}
unftdfkk

unftdfkk3#

您必须使用此内容模板修改默认的ContentDialog,或创建新样式以在ContentDialog中使用它:

<Style x:Key="MyCustomToolsContentDialog"
    TargetType="ContentDialog">
<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>
                                <!-- Modify to 'Height="*"' intead of 'Height="Auto"'-->
                                <RowDefinition Height="*" />
                                <!-- Modify to 'Height="Auto"' intead of 'Height="*"'-->
                                <RowDefinition Height="Auto" />
                                <!-- Delete' RowDefinition -->
                                <!--<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" />
                                        <!-- Delete 'Height="Auto"' of RowDefinition.-->
                                        <RowDefinition />
                                    </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>

希望这对你有帮助。
问候娟露

f3temu5u

f3temu5u4#

对于WinUI 3(Windows应用程序开发工具包):
这个解决方案与@Markus Hütter的解决方案相似但稍有不同。
首先,请注意,一个简单的方法来获得复制和粘贴的默认模板,如@Markus Hütter所建议的,是将Style="{StaticResource DefaultContentDialogStyle}"添加到您的内容对话框,右键单击,并选择转到定义。您可以将样式设置保留在您的内容对话框中,稍后用新的样式名称替换样式名称(下面讨论)。
在我的应用程序中(我假设默认情况下,在所有WinUI 3应用程序中),样式存在于generic.xaml中。
将整个样式复制到App.xamlResourceDictionary中,并将样式中的ScrollViewerDisabled设置更改为Auto,如下所示:

<ScrollViewer x:Name="ContentScrollViewer" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" ZoomMode="Disabled" IsTabStop="False">

此外,为新的自定义样式指定一个唯一的名称,例如:

<Style x:Key="MyCustomScrollableContentDialogStyle" TargetType="ContentDialog"> ...

注意,如上所述,您的ContentDialog需要使用Style="{StaticResource MyCustomScrollableContentDialogStyle}"引用新样式名称
这是有点长,但这是我的最终风格:

<!-- Derived from Default style for Windows.UI.Xaml.Controls.ContentDialog. Scrollviewer settings were changed in this version -->
        <Style x:Key="SSXScrollableContentDialogStyle" TargetType="ContentDialog">
            <Setter Property="Foreground" Value="{ThemeResource ContentDialogForeground}" />
            <Setter Property="Background" Value="{ThemeResource ContentDialogBackground}" />
            <Setter Property="BorderThickness" Value="{ThemeResource ContentDialogBorderWidth}" />
            <Setter Property="BorderBrush" Value="{ThemeResource ContentDialogBorderBrush}" />
            <Setter Property="IsTabStop" Value="False" />
            <Setter Property="PrimaryButtonStyle" Value="{ThemeResource DefaultButtonStyle}" />
            <Setter Property="SecondaryButtonStyle" Value="{ThemeResource DefaultButtonStyle}" />
            <Setter Property="CloseButtonStyle" Value="{ThemeResource DefaultButtonStyle}" />
            <Setter Property="CornerRadius" Value="{ThemeResource OverlayCornerRadius}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ContentDialog">
                        <Border x:Name="Container">

                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="DialogShowingStates">

                                    <VisualStateGroup.Transitions>
                                        <VisualTransition To="DialogHidden">

                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="Visibility">
                                                    <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible" />
                                                </ObjectAnimationUsingKeyFrames>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="IsHitTestVisible">
                                                    <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="False" />
                                                </ObjectAnimationUsingKeyFrames>
                                                <DoubleAnimationUsingKeyFrames Storyboard.TargetName="ScaleTransform" Storyboard.TargetProperty="ScaleX">
                                                    <DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="1.0" />
                                                    <SplineDoubleKeyFrame KeyTime="{StaticResource ControlFastAnimationDuration}" KeySpline="{StaticResource ControlFastOutSlowInKeySpline}" Value="1.05" />
                                                </DoubleAnimationUsingKeyFrames>
                                                <DoubleAnimationUsingKeyFrames Storyboard.TargetName="ScaleTransform" Storyboard.TargetProperty="ScaleY">
                                                    <DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="1.0" />
                                                    <SplineDoubleKeyFrame KeyTime="{StaticResource ControlFastAnimationDuration}" KeySpline="{StaticResource ControlFastOutSlowInKeySpline}" Value="1.05" />
                                                </DoubleAnimationUsingKeyFrames>
                                                <DoubleAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="Opacity">
                                                    <DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="1.0" />
                                                    <LinearDoubleKeyFrame KeyTime="{StaticResource ControlFasterAnimationDuration}" Value="0.0" />
                                                </DoubleAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualTransition>
                                        <VisualTransition To="DialogShowing">

                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="Visibility">
                                                    <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible" />
                                                </ObjectAnimationUsingKeyFrames>
                                                <DoubleAnimationUsingKeyFrames Storyboard.TargetName="ScaleTransform" Storyboard.TargetProperty="ScaleX">
                                                    <DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="1.05" />
                                                    <SplineDoubleKeyFrame KeyTime="{StaticResource ControlNormalAnimationDuration}" KeySpline="{StaticResource ControlFastOutSlowInKeySpline}" Value="1.0" />
                                                </DoubleAnimationUsingKeyFrames>
                                                <DoubleAnimationUsingKeyFrames Storyboard.TargetName="ScaleTransform" Storyboard.TargetProperty="ScaleY">
                                                    <DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="1.05" />
                                                    <SplineDoubleKeyFrame KeyTime="{StaticResource ControlNormalAnimationDuration}" KeySpline="{StaticResource ControlFastOutSlowInKeySpline}" Value="1.0" />
                                                </DoubleAnimationUsingKeyFrames>
                                                <DoubleAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="Opacity">
                                                    <DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="0.0" />
                                                    <LinearDoubleKeyFrame KeyTime="{StaticResource ControlFasterAnimationDuration}" Value="1.0" />
                                                </DoubleAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualTransition>
                                    </VisualStateGroup.Transitions>
                                    <VisualState x:Name="DialogHidden" />
                                    <VisualState x:Name="DialogShowing">
                                        <VisualState.Setters>
                                            <Setter Target="PrimaryButton.IsTabStop" Value="True" />
                                            <Setter Target="SecondaryButton.IsTabStop" Value="True" />
                                            <Setter Target="CloseButton.IsTabStop" Value="True" />
                                            <Setter Target="LayoutRoot.Visibility" Value="Visible" />
                                            <Setter Target="BackgroundElement.TabFocusNavigation" Value="Cycle" />

                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState x:Name="DialogShowingWithoutSmokeLayer">
                                        <VisualState.Setters>
                                            <Setter Target="PrimaryButton.IsTabStop" Value="True" />
                                            <Setter Target="SecondaryButton.IsTabStop" Value="True" />
                                            <Setter Target="CloseButton.IsTabStop" Value="True" />
                                            <Setter Target="LayoutRoot.Visibility" Value="Visible" />
                                            <Setter Target="LayoutRoot.Background" Value="{x:Null}" />

                                        </VisualState.Setters>
                                    </VisualState>

                                </VisualStateGroup>
                                <VisualStateGroup x:Name="DialogSizingStates">
                                    <VisualState x:Name="DefaultDialogSizing" />
                                    <VisualState x:Name="FullDialogSizing">
                                        <VisualState.Setters>
                                            <Setter Target="BackgroundElement.VerticalAlignment" Value="Stretch" />

                                        </VisualState.Setters>
                                    </VisualState>

                                </VisualStateGroup>
                                <VisualStateGroup x:Name="ButtonsVisibilityStates">
                                    <VisualState x:Name="AllVisible">
                                        <VisualState.Setters>
                                            <Setter Target="FirstSpacer.Width" Value="{ThemeResource ContentDialogButtonSpacing}" />
                                            <Setter Target="SecondaryColumn.Width" Value="*" />
                                            <Setter Target="SecondaryButton.(Grid.Column)" Value="2" />

                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState x:Name="NoneVisible">
                                        <VisualState.Setters>
                                            <Setter Target="CommandSpace.Visibility" Value="Collapsed" />

                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState x:Name="PrimaryVisible">
                                        <VisualState.Setters>
                                            <Setter Target="PrimaryButton.(Grid.Column)" Value="4" />
                                            <Setter Target="SecondaryButton.Visibility" Value="Collapsed" />
                                            <Setter Target="CloseButton.Visibility" Value="Collapsed" />

                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState x:Name="SecondaryVisible">
                                        <VisualState.Setters>
                                            <Setter Target="SecondaryButton.(Grid.Column)" Value="4" />
                                            <Setter Target="PrimaryButton.Visibility" Value="Collapsed" />
                                            <Setter Target="CloseButton.Visibility" Value="Collapsed" />

                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState x:Name="CloseVisible">
                                        <VisualState.Setters>
                                            <Setter Target="PrimaryButton.Visibility" Value="Collapsed" />
                                            <Setter Target="SecondaryButton.Visibility" Value="Collapsed" />

                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState x:Name="PrimaryAndSecondaryVisible">
                                        <VisualState.Setters>
                                            <Setter Target="SecondaryButton.(Grid.Column)" Value="4" />
                                            <Setter Target="CloseButton.Visibility" Value="Collapsed" />

                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState x:Name="PrimaryAndCloseVisible">
                                        <VisualState.Setters>
                                            <Setter Target="SecondaryButton.Visibility" Value="Collapsed" />

                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState x:Name="SecondaryAndCloseVisible">
                                        <VisualState.Setters>
                                            <Setter Target="PrimaryButton.Visibility" Value="Collapsed" />

                                        </VisualState.Setters>
                                    </VisualState>

                                </VisualStateGroup>
                                <VisualStateGroup x:Name="DefaultButtonStates">
                                    <VisualState x:Name="NoDefaultButton" />
                                    <VisualState x:Name="PrimaryAsDefaultButton">
                                        <VisualState.Setters>
                                            <Setter Target="PrimaryButton.Style" Value="{StaticResource AccentButtonStyle}" />

                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState x:Name="SecondaryAsDefaultButton">
                                        <VisualState.Setters>
                                            <Setter Target="SecondaryButton.Style" Value="{StaticResource AccentButtonStyle}" />

                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState x:Name="CloseAsDefaultButton">
                                        <VisualState.Setters>
                                            <Setter Target="CloseButton.Style" Value="{StaticResource AccentButtonStyle}" />

                                        </VisualState.Setters>
                                    </VisualState>

                                </VisualStateGroup>
                                <VisualStateGroup x:Name="DialogBorderStates">
                                    <VisualState x:Name="NoBorder" />
                                    <VisualState x:Name="AccentColorBorder">
                                        <VisualState.Setters>
                                            <Setter Target="BackgroundElement.BorderBrush" Value="{ThemeResource SystemControlForegroundAccentBrush}" />

                                        </VisualState.Setters>
                                    </VisualState>

                                </VisualStateGroup>

                            </VisualStateManager.VisualStateGroups>
                            <Grid x:Name="LayoutRoot" Visibility="Collapsed">
                                <Rectangle x:Name="SmokeLayerBackground" Fill="{ThemeResource ContentDialogSmokeFill}" />
                                <Border x:Name="BackgroundElement" Background="{TemplateBinding Background}" FlowDirection="{TemplateBinding FlowDirection}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" BackgroundSizing="InnerBorderEdge" CornerRadius="{TemplateBinding CornerRadius}" MinWidth="{ThemeResource ContentDialogMinWidth}" MaxWidth="{ThemeResource ContentDialogMaxWidth}" MinHeight="{ThemeResource ContentDialogMinHeight}" MaxHeight="{ThemeResource ContentDialogMaxHeight}" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5">
                                    <Border.RenderTransform>
                                        <ScaleTransform x:Name="ScaleTransform" />
                                    </Border.RenderTransform>
                                    <Grid x:Name="DialogSpace" CornerRadius="{ThemeResource OverlayCornerRadius}">
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="*" />
                                            <RowDefinition Height="Auto" />
                                        </Grid.RowDefinitions>
                                        <ScrollViewer x:Name="ContentScrollViewer" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" ZoomMode="Disabled" IsTabStop="False">
                                            <Grid Background="{ThemeResource ContentDialogTopOverlay}" Padding="{ThemeResource ContentDialogPadding}" BorderThickness="{ThemeResource ContentDialogSeparatorThickness}" BorderBrush="{ThemeResource ContentDialogSeparatorBorderBrush}">
                                                <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="{StaticResource ContentControlThemeFontFamily}" FontWeight="SemiBold" 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="{StaticResource ControlContentThemeFontSize}" FontFamily="{StaticResource ContentControlThemeFontFamily}" Foreground="{TemplateBinding Foreground}" Grid.Row="1" TextWrapping="Wrap" />
                                            </Grid>
                                        </ScrollViewer>
                                        <Grid x:Name="CommandSpace" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" XYFocusKeyboardNavigation="Enabled" Padding="{ThemeResource ContentDialogPadding}" Background="{TemplateBinding Background}">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition x:Name="PrimaryColumn" Width="*" />
                                                <ColumnDefinition x:Name="FirstSpacer" Width="0" />
                                                <ColumnDefinition x:Name="SecondaryColumn" Width="0" />
                                                <ColumnDefinition x:Name="SecondSpacer" Width="{ThemeResource ContentDialogButtonSpacing}" />
                                                <ColumnDefinition x:Name="CloseColumn" Width="*" />
                                            </Grid.ColumnDefinitions>
                                            <Button x:Name="PrimaryButton" IsTabStop="False" Content="{TemplateBinding PrimaryButtonText}" IsEnabled="{TemplateBinding IsPrimaryButtonEnabled}" Style="{TemplateBinding PrimaryButtonStyle}" ElementSoundMode="FocusOnly" HorizontalAlignment="Stretch" />
                                            <Button x:Name="SecondaryButton" IsTabStop="False" Content="{TemplateBinding SecondaryButtonText}" IsEnabled="{TemplateBinding IsSecondaryButtonEnabled}" Style="{TemplateBinding SecondaryButtonStyle}" ElementSoundMode="FocusOnly" HorizontalAlignment="Stretch" />
                                            <Button x:Name="CloseButton" IsTabStop="False" Grid.Column="4" Content="{TemplateBinding CloseButtonText}" Style="{TemplateBinding CloseButtonStyle}" ElementSoundMode="FocusOnly" HorizontalAlignment="Stretch" />
                                        </Grid>

                                    </Grid>
                                </Border>

                            </Grid>
                        </Border>

                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

相关问题