我在使网格列变为全宽时遇到困难。如您所见,我在文本块上尝试了HorizontalAlignment =“ Stretch”(还尝试了Center),在宽度上尝试了Width =“ *”(也尝试了Auto),但似乎都没有用。
我希望该列是整个窗口的宽度,而'欢迎'文本应居中。
<Grid>
<DockPanel LastChildFill="False">
<TextBlock DockPanel.Dock="Top" Text="Drink & Drive"/>
<TextBlock DockPanel.Dock="Bottom" Text="Drink & Drive - 2020"/>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" HorizontalAlignment="Stretch" Text="WELCOME"/>
</Grid>
</DockPanel>
</Grid>
结果:
谢谢。
我建议使用1个网格,而不是网格+ DockPanel +网格
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="Drink & Drive"/>
<TextBlock Grid.Row="1" Text="WELCOME" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Grid.Row="2" Text="Drink & Drive - 2020"/>
</Grid>