我正在尝试使用包含2列和6行的网格编写通用应用,每个包含一个文本块。我希望网格能够随窗口大小自动缩放,稍后我将通过窗口缩放文本。
<Grid HorizontalAlignment="Left" Height="1070" Margin="10,10,0,0" VerticalAlignment="Top" Width="1900">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock x:Name="DaoTB" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="TEST" VerticalAlignment="Top" Height="154" Width="736" FontSize="100" TextAlignment="Center" SelectionChanged="textBlock_SelectionChanged" Grid.Column="1" Grid.Row="0"/>
<TextBlock x:Name="EthTB" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="TEST" VerticalAlignment="Top" Height="154" Width="736" FontSize="100" TextAlignment="Center" SelectionChanged="textBlock_SelectionChanged" Grid.Column="1" Grid.Row="1"/>
<TextBlock x:Name="LtcTB" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="TEST" VerticalAlignment="Top" Height="154" Width="736" FontSize="100" TextAlignment="Center" SelectionChanged="textBlock_SelectionChanged" Grid.Column="1" Grid.Row="2"/>
<TextBlock x:Name="DgeTB" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="TEST" VerticalAlignment="Top" Height="154" Width="736" FontSize="100" TextAlignment="Center" SelectionChanged="textBlock_SelectionChanged" Grid.Column="1" Grid.Row="3"/>
<TextBlock x:Name="LumTB" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="TEST" VerticalAlignment="Top" Height="154" Width="736" FontSize="100" TextAlignment="Center" SelectionChanged="textBlock_SelectionChanged" Grid.Column="1" Grid.Row="4"/>
<TextBlock x:Name="RipTB" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="TEST" VerticalAlignment="Top" Height="154" Width="736" FontSize="100" TextAlignment="Center" SelectionChanged="textBlock_SelectionChanged" Grid.Column="1" Grid.Row="5"/>
</Grid>
这不会随窗口自动缩放 - 文本会从屏幕上移开,当我调整窗口大小时,文本会保持原位并离开屏幕。如何根据窗口大小调整网格大小?
答案 0 :(得分:1)
如果你想让它延伸到窗口边界,你的网格应该是这样的
<Grid Margin="10,10,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock x:Name="DaoTB" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="TEST" VerticalAlignment="Top" Height="154" Width="736" FontSize="100" TextAlignment="Center" SelectionChanged="textBlock_SelectionChanged" Grid.Column="1" Grid.Row="0"/>
<TextBlock x:Name="EthTB" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="TEST" VerticalAlignment="Top" Height="154" Width="736" FontSize="100" TextAlignment="Center" SelectionChanged="textBlock_SelectionChanged" Grid.Column="1" Grid.Row="1"/>
<TextBlock x:Name="LtcTB" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="TEST" VerticalAlignment="Top" Height="154" Width="736" FontSize="100" TextAlignment="Center" SelectionChanged="textBlock_SelectionChanged" Grid.Column="1" Grid.Row="2"/>
<TextBlock x:Name="DgeTB" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="TEST" VerticalAlignment="Top" Height="154" Width="736" FontSize="100" TextAlignment="Center" SelectionChanged="textBlock_SelectionChanged" Grid.Column="1" Grid.Row="3"/>
<TextBlock x:Name="LumTB" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="TEST" VerticalAlignment="Top" Height="154" Width="736" FontSize="100" TextAlignment="Center" SelectionChanged="textBlock_SelectionChanged" Grid.Column="1" Grid.Row="4"/>
<TextBlock x:Name="RipTB" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="TEST" VerticalAlignment="Top" Height="154" Width="736" FontSize="100" TextAlignment="Center" SelectionChanged="textBlock_SelectionChanged" Grid.Column="1" Grid.Row="5"/>
</Grid>