[英]In WPF, is there a way to make a StackPanel with aligned columns like a Grid?
[英]WPF Grid Quick Way to Make Columns and Rows
假設我需要制作一個30列30行的。 我必須做30次<ColumnDefinition></ColumnDefinition>
和<RowDefinition></RowDefinition>
嗎? 有沒有簡單/快速的方法?
我必須做30次
<ColumnDefinition></ColumnDefinition>
和<RowDefinition></RowDefinition>
嗎? 有沒有簡單/快速的方法?
使用普通的for循環以編程方式創建它們:
public MainWindow()
{
InitializeComponent();
const int n = 30;
for (int i = 0; i < n; ++i)
{
grid.ColumnDefinitions.Add(new ColumnDefinition());
grid.RowDefinitions.Add(new RowDefinition());
}
}
XAML:
<Grid x:Name="grid" />
再簡單不過了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.