Windows 8 包裹面板 [英] Windows 8 WrapPanel

查看:24
本文介绍了Windows 8 包裹面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了自动将 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 包裹面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆