I have the following:
我有以下几点:
<DockPanel Height="25" HorizontalAlignment="Stretch">
<Button Content="Add" x:Name="bAdd" DockPanel.Dock="Left" />
<Button Content="Remove" x:Name="bRemove" DockPanel.Dock="Right" />
</DockPanel>
Can someone suggest me how to make both the buttons have equal width without setting the Width
property of the buttons manually?
是否有人建议我如何使两个按钮的宽度相等而不需要手动设置按钮的宽度属性?
2 个解决方案
#1
6
If you absolutely don't want to set the Width
propety, you can just use a Grid
:
如果你绝对不想设置宽度,你可以使用一个网格:
<Grid Height="25" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Content="Add" x:Name="bAdd" />
<Button Grid.Column="1" Content="Remove" x:Name="bRemove" />
</Grid>
They will both have the same Width
this way
它们的宽度都是一样的
#2
2
<UniformGrid HorizontalAlignment="Right" Rows="1" Columns="2">
<Button Content="Ok" Grid.Column="0"/>
<Button Content="Cancel" Grid.Column="1"/>
</UniformGrid>
#1
6
If you absolutely don't want to set the Width
propety, you can just use a Grid
:
如果你绝对不想设置宽度,你可以使用一个网格:
<Grid Height="25" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Content="Add" x:Name="bAdd" />
<Button Grid.Column="1" Content="Remove" x:Name="bRemove" />
</Grid>
They will both have the same Width
this way
它们的宽度都是一样的
#2
2
<UniformGrid HorizontalAlignment="Right" Rows="1" Columns="2">
<Button Content="Ok" Grid.Column="0"/>
<Button Content="Cancel" Grid.Column="1"/>
</UniformGrid>