1

例如,我有这个标记:

<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 完成这样的任务?

4

3 回答 3

3

尝试使用Gridwith 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>
于 2013-10-02T10:45:23.093 回答
0

您还可以使用统一的网格来确保所有按钮的大小相同。

于 2013-10-02T11:26:27.473 回答
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>
于 2013-10-02T11:39:26.450 回答