我即将在***UWP应用程序***中创建Grid Matrix,但遇到了Button控件无法拉伸以填充可用空间的问题;如何强制Button控件的行为类似于TextBox?
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.Resources>
<Style TargetType="Button">
<Setter Property="BorderBrush" Value="Yellow" />
<Setter Property="BorderThickness" Value="5" />
</Style>
<Style TargetType="TextBox">
<Setter Property="BorderBrush" Value="Yellow" />
<Setter Property="BorderThickness" Value="5" />
</Style>
</Grid.Resources>
<TextBox Grid.Row="0" Grid.Column="0" Text="One" />
<TextBox Grid.Row="0" Grid.Column="1" Text="Two" />
<Button Grid.Row="1" Grid.Column="0" Content="Three" />
<Button Grid.Row="1" Grid.Column="1" Content="Four" />
</Grid>
1条答案
按热度按时间ssm49v7z1#
只需将这两个属性添加到按钮中即可:
水平对齐=“拉伸”
垂直对齐=“拉伸”
最终按钮定义:
另外,这些属性需要被覆盖的原因是,在Button的默认样式模板中,它们被默认地分别通过Setter设置为Left/Center。