Windows 8 WrapPanel [英] Windows 8 WrapPanel
问题描述
我在自动将StackPanel拆分到下一行时遇到问题.这是示例代码:
I've got problem with automatically breaking StackPanel into next line. Here's the sample code:
<StackPanel Orientation="Horizontal" Width="180">
<TextBlock.../>
<TextBlock.../>
<TextBlock.../>
<Image.../>
...
</StackPanel>
现在,我要达到这样的效果:当StackPanel中没有足够的空间容纳另一个元素时,应将其放置在新行中.我该如何做到这一点(不必使用stackpanel)?
Now I want to achive something like this: when there is not enough space for another element in the StackPanel it should be placed in new line. How I can achive this (it's not necessary to use stackpanel)?
PS:我的目标是将文本和图像放在一行中(当没有足够的空间放置另一元素时,它可能会中断).也许您可以提供比使用文本块和图像更好的解决方案?
PS: My goal is to place text and images in one line (it can of course break, when there is not enough space for another element). Maybe you can provide better solution than using textblocks and images?
推荐答案
尝试WrapGrid,它应该做您想要的事情: http://msdn.microsoft .com/en-us/library/windows/apps/windows.ui.xaml.controls.wrapgrid.aspx
Try the WrapGrid, it should do what you want: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.wrapgrid.aspx
唯一的收获(这不是一件坏事)是WrapGrid只能在ItemsControl中显示项目,因此使用这种方式(将ListView更改为任何ItemsControl):
The only catch (which isn't a bad thing) is that WrapGrid can only display items in an ItemsControl, so use it this way (changing ListView to any ItemsControl):
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapGrid Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
这篇关于Windows 8 WrapPanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!