carlzj
carlzj
采纳率92.9%
2016-06-28 13:37 阅读 1.4k
已采纳

写UWP应用,Xaml如何实现多个按钮水平放置平分窗口大小

写UWP应用,Xaml如何实现多个按钮水平放置平分窗口大小?

这样写的话不能水平平分,有什么别的方法吗?

<StackPanel x:Name="First" Orientation="Horizontal" Margin="0,0,0,496" Grid.Row="1">
      <Button x:Name="Number1" Content="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
      <Button x:Name="Number2" Content="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
      <Button x:Name="Number3" Content="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
</StackPanel>

最终要实现的样子是改变窗口大小的同时,按钮大小也跟随改变,且所有按钮大小相等。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    carlzj carlzj 2016-06-29 02:53

    没人回答我自己解决了。。

    <Grid Margin="0" 
          Grid.Row="1" 
          HorizontalAlignment="Stretch" 
          VerticalAlignment="Stretch">
          <Grid.RowDefinitions>
               <RowDefinition Height="*" />
               <RowDefinition Height="*" />
               <RowDefinition Height="*" />
               <RowDefinition Height="*" />
          </Grid.RowDefinitions>
    
               <Grid.ColumnDefinitions>
               <ColumnDefinition Width="*"/>
               <ColumnDefinition Width="*"/>
               <ColumnDefinition Width="*"/>
               <ColumnDefinition Width="*"/>
          </Grid.ColumnDefinitions>
    
                <Button x:Name="Number1" 
                        Grid.Row="0" 
                        Grid.Column="0"
                        Content="1" 
                        MinHeight="30" 
                        MinWidth="30" 
                        HorizontalAlignment="Stretch" 
                        VerticalAlignment="Stretch" 
                        Click="Number1_Click"/>
    
          <Button x:Name="Number2" 
                        Grid.Row="0" 
                        Grid.Column="1"
                        Content="2" 
                        MinHeight="30" 
                        MinWidth="30" 
                        HorizontalAlignment="Stretch" 
                        VerticalAlignment="Stretch" 
                                            Click="Number2_Click"/>
    
          <Button x:Name="Number3" 
                        Grid.Row="0" 
                        Grid.Column="2"
                        Content="3" 
                        MinHeight="30" 
                        MinWidth="30" 
                        HorizontalAlignment="Stretch" 
                        VerticalAlignment="Stretch" Click="Number3_Click"/>
    </Grid>
    
    

    这样就好了。

    点赞 评论 复制链接分享

相关推荐