我怎样才能达到的StackPanel和UniformGrid行为这个组合? [英] How can I achieve this mix of StackPanel and UniformGrid behavior?

查看:197
本文介绍了我怎样才能达到的StackPanel和UniformGrid行为这个组合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望把元素的控件中,让他们开始适应这样的(如的StackPanel 与水平方向):

I want to put elements inside a control so that they initially fit like this (like a StackPanel with Horizontal orientation):

但是,当元素堆叠到如此地步,他们将不适合再在屏幕上,我想他们开始表现是这样的:

But then, when the elements stack to the point they won't fit anymore in the screen, I want them to start behaving like this:

如同 UniformGrid :作为元素的数量的增加,它们变得更小。

Like an UniformGrid: as the number of elements increase, they become smaller.

什么是最好的或任何方式做到这一点?由于外部控制大小是可变的(这取决于用户的屏幕尺寸)我不能黑客它使用一个部件或另一个取决于元件的数量,因为我无法预测它采取中断的数目屏幕。

What would be the best or any way to do this? Since the external control size is variable (it depends on the user's screen size) I can't "hack" it to use one component or another depending on the number of elements because I can't predict the number it takes to "break" the screen.

推荐答案

最简单的/最快的路线,把它扔在视框将其设置为拉伸=统一来为你做它,像下面,只需加/减矩形,你会得到这个概念的例子...

Easiest/Quickest route, throw it in a ViewBox with it set to Stretch="Uniform" to do it for you, as an example like below, just add/subtract rectangles and you'll get the concept...

<Viewbox Stretch="Uniform" MaxHeight="60" MaxWidth="200">
    <StackPanel Orientation="Horizontal">
         <Rectangle Fill="Red" Margin="5" Height="50" Width="50"/>
         <Rectangle Fill="Red" Margin="5" Height="50" Width="50"/>
         <Rectangle Fill="Red" Margin="5" Height="50" Width="50"/>
         <Rectangle Fill="Red" Margin="5" Height="50" Width="50"/>
         <Rectangle Fill="Red" Margin="5" Height="50" Width="50"/>
         <Rectangle Fill="Red" Margin="5" Height="50" Width="50"/>
         <Rectangle Fill="Red" Margin="5" Height="50" Width="50"/>
         <Rectangle Fill="Red" Margin="5" Height="50" Width="50"/>
         <Rectangle Fill="Red" Margin="5" Height="50" Width="50"/>
         <Rectangle Fill="Red" Margin="5" Height="50" Width="50"/>
     </StackPanel>
</Viewbox>



希望这有助于。干杯

Hope this helps. Cheers

这篇关于我怎样才能达到的StackPanel和UniformGrid行为这个组合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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