WrapPanel控件
WrapPanel基本上是带很多额外特性的StackPanel。几个月前我在创建了一个游戏,我想在一个屏幕里面放置30个按钮。因为那时还没有WrapPanel,我不得不去动态的创建一个Grid,然后再将每个按钮放在Grid中的某个位置上。这些工作比我想象的要多得多,而仅仅是为了在一个5x6的布局中放30个按钮。现在WrapPanel帮我们解决了这个问题。
在下面的例子中,我在一个WrapPanel中放置了12个按钮。
<toolkit:WrapPanel>
<Button Width="75" Height="75" Content="1" />
<Button Width="75" Height="75" Content="2" />
<Button Width="75" Height="75" Content="3" />
<Button Width="75" Height="75" Content="4" />
<Button Width="75" Height="75" Content="5" />
<Button Width="75" Height="75" Content="6" />
<Button Width="75" Height="75" Content="7" />
<Button Width="75" Height="75" Content="8" />
<Button Width="75" Height="75" Content="9" />
<Button Width="75" Height="75" Content="10" />
<Button Width="75" Height="75" Content="11" />
<Button Width="75" Height="75" Content="12" />
</toolkit:WrapPanel>
<Button Width="75" Height="75" Content="1" />
<Button Width="75" Height="75" Content="2" />
<Button Width="75" Height="75" Content="3" />
<Button Width="75" Height="75" Content="4" />
<Button Width="75" Height="75" Content="5" />
<Button Width="75" Height="75" Content="6" />
<Button Width="75" Height="75" Content="7" />
<Button Width="75" Height="75" Content="8" />
<Button Width="75" Height="75" Content="9" />
<Button Width="75" Height="75" Content="10" />
<Button Width="75" Height="75" Content="11" />
<Button Width="75" Height="75" Content="12" />
</toolkit:WrapPanel>
在我下面的代码示例中,你会看到我为Button 1和Button 2配备了事件处理程序。它们可以让所有按钮的尺寸放大或缩小。在把玩这个例子时应该仔细看看WrapPanel是如何动态移动你的内容的,尤其是在运行时。下面是相同代码的截图,只不过其中的按钮被刻意地放大了:
好了,就是这些!我们讲解了Silverlight Toolkit for Windows Phone中5个全新的可用控件。请在今天就下载它,因为你会发现很快就会用到它。