如何避免WPF窗口缩小其维度

时间:2016-10-10 14:07:45

标签: wpf xaml window size

我看了几篇文章,但我无法解决这个问题。

我的Grid定义如下:

<Grid>
   <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="2*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
   </Grid.ColumnDefinitions>
   ...

在第一行中我希望Border内置TextBlock。我需要Border始终具有相同的大小而不受TextBlock的影响。

<Grid Grid.Row="0">
       <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
                <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Border Grid.Row="0" BorderBrush="{DynamicResource StandardBorderColor}" BorderThickness="2" Margin="15,10,15,10"
                    HorizontalAlignment="Stretch"/>

        <TextBlock Grid.Row="0" Name="TextBlock" Margin="20, 15, 20, 20"
                   TextWrapping="Wrap" Foreground="{DynamicResource StandardForegroundColor}" FontSize="18" FontWeight="Bold"
                   VerticalAlignment="Center" TextAlignment="Left" Text="{Binding Testo}" HorizontalAlignment="Stretch"/>
</Grid>

你有什么建议吗?提前谢谢!

更新

Initial condition

Second condition

解决方案:

我发现这是解决方案:

<Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="2*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>


        <GroupBox HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"
                  VerticalAlignment="Stretch" VerticalContentAlignment="Stretch"
                  Margin="15, 10, 15, 10" Header="Avvisi">
            <TextBox x:Name="TextBlock" FontSize="16" 
                     VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"
                     TextAlignment="Left" Text="{Binding Testo}" Style="{DynamicResource TxtBoxStyle}" ScrollViewer.VerticalScrollBarVisibility="Visible"
                     BorderBrush="Transparent" IsReadOnly="True" />
        </GroupBox>
   ...

0 个答案:

没有答案