我有4個按鈕在網格內對齊。有沒有什麼方法可以自動對齊,如果一個按鈕的可見性設置爲false,其餘的按鈕會明智地使用該空間[其他按鈕移動以適應新的空間]?按鈕自動對齊
Q
按鈕自動對齊
3
A
回答
2
而不是一個網格,將按鈕放在一個方向=「水平」的StackPanel。另外,請確保將按鈕可見性設置爲「摺疊」而不是「隱藏」。
1
取決於佈局以及您希望空間分佈的複雜程度,如果均勻分佈足夠您可以使用UniformGrid
,在正常的Grid
中,由於需要調整列和行會有點棘手。
2
嘗試以下操作:
<Grid VerticalAlignment="Center" HorizontalAlignment="Center">
<StackPanel Orientation="Horizontal">
<Button Content="1" Width="50" Height="23" Visibility="Collapsed"/>
<Button Content="2" Width="50" Height="23"/>
<Button Content="3" Width="50" Height="23" Visibility="Collapsed"/>
<Button Content="4" Width="50" Height="23"/>
</StackPanel>
</Grid>
或者這樣:
<Grid VerticalAlignment="Center" HorizontalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="1" Content="1" Width="50" Height="23" Visibility="Collapsed"/>
<Button Grid.Column="2" Content="2" Width="50" Height="23"/>
<Button Grid.Column="3" Content="3" Width="50" Height="23" Visibility="Collapsed"/>
<Button Grid.Column="4" Content="4" Width="50" Height="23"/>
</Grid>
你應該看到的按鈕爲中心,但只顯示了第二個和第四個按鈕
相關問題
- 1. 如何自動對齊按鈕
- 2. ionic2:menuToggle按鈕對齊到右自動
- 3. 動作欄對齊按鈕
- 4. 按鈕對齊
- 5. 對齊按鈕
- 6. 對齊按鈕組
- 7. Python按鈕對齊
- 8. Wpf對齊按鈕
- 9. 對齊按鈕DIV
- 10. Android按鈕對齊
- 11. RadioGroup /按鈕對齊
- 12. Xamarin.forms按鈕對齊
- 13. ExtJS按鈕對齊
- 14. 自舉輸入組和按鈕對齊
- 15. 自舉輸入組按鈕右對齊
- 16. 自定義按鈕樣式對齊wpf
- 17. 自定義按鈕內容對齊
- 18. 中心對齊自舉導航按鈕
- 19. 對齊對象和按鈕
- 20. 右對齊按鈕垂直未對齊
- 21. 動態單選按鈕文本對齊
- 22. jquery移動單選按鈕對齊
- 23. 在浮動上對齊提交按鈕?
- 24. jQuery移動按鈕對齊問題
- 25. 切換按鈕的動態對齊
- 26. jquery移動對齊的拆分按鈕
- 27. 對齊jQuery移動滑塊與按鈕
- 28. 對齊按鈕到底部(浮動)
- 29. CSS滑動門按鈕中心對齊
- 30. 按鈕對齊彈出式按鈕