2017-10-13 48 views
0

假設我有一個網格,其中有很多按鈕,我想要實現的是我想對齊左上角的按鈕以及當我更改窗口的大小時網格的大小會改變,按鈕將自動重新排列。 我的XAML代碼會像網格中的自動垂直和水平對齊WPF

<Grid HorizontalAlignment="Left" VerticalAlignment="Top"> 

     <Grid.Resources> 
      <Style TargetType="{x:Type Button}"> 
       <Setter Property="Width" Value="100" /> 
       <Setter Property="Height" Value="100" /> 

      </Style> 

     </Grid.Resources> 
     <Button Content="Button1" /> 
     <Button Content="Button2" /> 
     <Button Content="Button3" /> 
     <Button Content="Button4" /> 
     <Button Content="Button5" /> 
     <Button Content="Button6" /> 

    </Grid> 

我是一個web開發者,它的超級容易做到這一點在CSS & HTML。

https://codepen.io/anon/pen/gGdrJJ

+9

有用['WrapPanel'(https://wpftutorial.net/WrapPanel.html)? – Sinatr

+0

這實際上工作,以及我感到非常驚訝,因爲我做了很多搜索,無論如何,謝謝。 –

+1

您可能錯過了[面板概述](https://docs.microsoft.com/en-us/dotnet/framework/wpf/controls/panels-overview)。 – Clemens

回答