ContentDialog的大小不适合具有大型TextBlock

时间:2015-10-09 12:15:23

标签: xaml win-universal-app uwp

我正在尝试为通用应用构建自定义ContentDialog。但是,当其中一个文本块是多行的时,窗口大小会过大。这是布局:

<ContentDialog
    x:Class="a2v.ConflictDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:a2v"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="1000"
    d:DesignWidth="1000"
    VerticalAlignment="Stretch"
    HorizontalAlignment="Stretch"
    Height="Auto"
    Width="Auto"
    Title="Conflict">

    <Grid Width="Auto" Height="Auto">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.Resources>
            <Style x:Key="ButtonStyle" TargetType="Button">
                <Setter Property="Background" Value="LightSkyBlue"/>
                <Setter Property="BorderThickness" Value="0"/>
                <Setter Property="HorizontalContentAlignment" Value="Center"/>
                <Setter Property="VerticalContentAlignment" Value="Center"/>
            </Style>
        </Grid.Resources>
        <!--<TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" x:Name="Text" TextAlignment="Justify" Text="ShortText" TextWrapping="WrapWholeWords"/>-->
        <TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" x:Name="Text" TextAlignment="Justify" Text="This long text illustrates how the big dialog content make the dialog window size very big. As soon as I change the text to somewhat smaller the empty space below disappears." TextWrapping="WrapWholeWords"/>
        <TextBlock Grid.Row="1" Grid.Column="0" Margin="0,15,0,0" Text="Remove conflicting"/>
        <TextBlock Grid.Row="1" Grid.Column="1" Margin="30,15,5,0" Text="-" VerticalAlignment="Top"/>
        <TextBlock Grid.Row="1" Grid.Column="2" Margin="0,15,0,0" Text="removes." TextWrapping="WrapWholeWords"/>
        <TextBlock Grid.Row="2" Grid.Column="0" Text="Resolve conflicting"/>
        <TextBlock Grid.Row="2" Grid.Column="1" Margin="30,0,0,0" Text="-" VerticalAlignment="Top" />
        <TextBlock Grid.Row="2" Grid.Column="2" Text="resolves." TextWrapping="WrapWholeWords"/>
        <TextBlock Grid.Row="3" Grid.Column="0" Text="Cancel" />
        <TextBlock Grid.Row="3" Grid.Column="1" Margin="30,0,0,0" Text="-" VerticalAlignment="Top" />
        <TextBlock Grid.Row="3" Grid.Column="2" Text="do nothing and return to the previous screen." TextWrapping="WrapWholeWords" />

        <Grid Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="3">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Button Grid.Column="0" Content="Remove conflicting" Margin="15,15,0,15" Style="{StaticResource ButtonStyle}" Tapped="RemoveConflict_OnTapped"/>
            <Button Grid.Column="1" Content="Resolve conflicting" Margin="15,15,0,15" Style="{StaticResource ButtonStyle}" Tapped="ResolveConflict_OnTapped"/>
            <Button Grid.Column="2" Content="Cancel" Margin="15,15,15,15" Style="{StaticResource ButtonStyle}" Tapped="Cancel_OnTapped"/>
        </Grid>
    </Grid>
</ContentDialog>

Here is how it looks like with the short text

And here is what happens when the text is long

如何摆脱对话框底部的空白区域?

1 个答案:

答案 0 :(得分:-1)

尝试为MaxHeight添加contentDialog值。