例如,我有这个标记:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center">
<Button x:Name="PreviousPage"
Content="Previous" />
<Button x:Name="Info"
Content="Information" />
<Button x:Name="InetTicket"
Content="Internet ticket" />
<Button x:Name="FindStation"
Content="Find station" />
<Button x:Name="NextPage"
Content="Next" />
</StackPanel>
</Grid>
如何确定最宽的按钮并与其他按钮共享它的大小。所以按钮的宽度应该相同。如何使用xaml完成这样的任务?
答案 0 :(得分:3)
尝试将Grid
与IsSharedSizeScope
一起使用,而不是StackPanel
,如下所示:
<Grid Grid.IsSharedSizeScope="true" HorizontalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="buttons"/>
<ColumnDefinition SharedSizeGroup="buttons"/>
<ColumnDefinition SharedSizeGroup="buttons"/>
<ColumnDefinition SharedSizeGroup="buttons"/>
<ColumnDefinition SharedSizeGroup="buttons"/>
</Grid.ColumnDefinitions>
<Button x:Name="PreviousPage" Content="Previous" Grid.Column="0"/>
<Button x:Name="Info" Content="Information" Grid.Column="1"/>
<Button x:Name="InetTicket" Content="Internet ticket" Grid.Column="2"/>
<Button x:Name="FindStation" Content="Find station" Grid.Column="3"/>
<Button x:Name="NextPage" Content="Next" Grid.Column="4"/>
</Grid>
答案 1 :(得分:0)
您还可以使用统一的网格,确保所有按钮的大小相同。
答案 2 :(得分:0)
使用UniformGrid
:
<UniformGrid Rows="1">
<Button x:Name="PreviousPage"
Content="Previous" />
<Button x:Name="Info"
Content="Information" />
<Button x:Name="InetTicket"
Content="Internet ticket" />
<Button x:Name="FindStation"
Content="Find station" />
<Button x:Name="NextPage"
Content="Next" />
</UniformGrid>