2010-03-31 23 views

回答

9

我想這是你想要什麼:

MyStackPanel.SetValue(Grid.RowProperty, 1); 
    MyStackPanel.SetValue(Grid.ColumnProperty, 2); 

希望這有助於

+0

現在看起來很簡單,我看到了代碼。謝謝。 – 2010-03-31 19:01:30

6

你應該能夠做到以下幾點,其中「myGrid」是你的Grid控件的名稱。

StackPanel stackPanel = new StackPanel(); 

Grid.SetColumn(stackPanel, 0); 
Grid.SetRow(stackPanel, 1); 

myGrid.Children.Add(stackPanel); 
+0

這也適用,但安東尼給了我第一個答案,所以他得到了接受。謝謝回覆。 – 2010-03-31 19:02:01

+0

從我的經驗來看,Rich的答案是更典型的WPF/Silverlight代碼,因爲它更像XAML(我一直認爲它更容易發現)。 – WiredPrairie 2010-04-01 01:43:06

+2

我實際上查了一下,Grid類的靜態方法實際調用了給定的UIElement的SetValue方法。 Obvsiouly都工作,只是歸結爲個人喜好。 – 2010-04-01 14:43:57

相關問題