天天看點

WP7 silverlight toolkit 學習之 WrapPanel 使用

xaml:

<toolkit:WrapPanel Height="300"

HorizontalAlignment="Left"

Margin="58,152,0,0"

Name="wrp"

VerticalAlignment="Top"

Width="350"

Orientation="Horizontal"/>

</Grid>

這是前台頁面,控件很簡單,也可以歸類到面闆類,這個控件會自動換行,不會層疊,你可以設定方向,垂直排列,也可以橫排列

cs:

private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)

{

for (int i = 0; i < 50; i++)

{

wrp.Children.Add(new Rectangle() { Width=50,Height=50,Fill=new SolidColorBrush(Colors.Yellow)});

wrp.Children.Add(new Rectangle() { Width = 50, Height = 50, Fill = new SolidColorBrush(Colors.Red) });

wrp.Children.Add(new Rectangle() { Width = 50, Height = 50, Fill = new SolidColorBrush(Colors.Blue) });

wrp.Children.Add(new Rectangle() { Width = 50, Height = 50, Fill = new SolidColorBrush(Colors.Green) });

wrp.Children.Add(new Rectangle() { Width = 50, Height = 50, Fill = new SolidColorBrush(Colors.White) });

}

}

你試下效果就知道了哦