2012-03-09 104 views
1

我讀到我可以使用Silverlight Toolkit創建列。 但我怎麼能用C#代碼來做到這一點,而不是用XAML? (在我的課)Windows Phone 7中的列

例如:

<toolkit:WrapPanel Orientation="Vertical" Height="400"> 
<Button Content="A" BorderBrush="Aqua" /> 
<Button Content="B" BorderBrush="CadetBlue" /> 
<Button Content="C" BorderBrush="DarkMagenta" /> 
<Button Content="D" BorderBrush="Fuchsia" /> 
<Button Content="F" BorderBrush="LightBlue" /> 
<Button Content="G" BorderBrush="Orange" /> 
</toolkit:WrapPanel> 

但我怎麼能與C#的功能做呢?

+0

柱的什麼?你應該畫一些用戶界面的例子,並添加一個圖片到你的問題的原因,現在我們不知道你真正想要什麼。 – ken2k 2012-03-09 15:57:14

回答

3

這裏是你如何寫同樣的事情在C#

var wp = new WrapPanel 
    { 
     Orientation = System.Windows.Controls.Orientation.Vertical, 
     Height = 400 
    }; 

wp.Children.Add(new Button { Content = "A", BorderBrush = new SolidColorBrush(Colors.Cyan) }); // Cyan is the same as Aqua 
wp.Children.Add(new Button { Content = "B", BorderBrush = new SolidColorBrush(Color.FromArgb(255, 95, 158, 160)) }); // CadetBlue 
wp.Children.Add(new Button { Content = "C", BorderBrush = new SolidColorBrush(Color.FromArgb(255, 139, 0, 139)) }); // DarkMagenta 
wp.Children.Add(new Button { Content = "D", BorderBrush = new SolidColorBrush(Colors.Magenta) }); // Fuschia is the same as Magenta 
wp.Children.Add(new Button { Content = "F", BorderBrush = new SolidColorBrush(Color.FromArgb(255, 173, 216, 230)) }); // LightBlue 
wp.Children.Add(new Button { Content = "G", BorderBrush = new SolidColorBrush(Colors.Orange) }); 

this.LayoutRoot.Children.Add(wp); 
+0

謝謝!但是另一個問題是:如果「LayoutRoot」不確定,我可以如何添加「wp」? – 2012-03-09 17:05:04

+0

由於您處於PhoneApplicationPage類(MainPage)中,因此可以將Content屬性設置爲wp。 – 2012-03-09 20:51:43