堆栈面板或网格哪一个最可取

发布于 2024-10-22 00:05:05 字数 129 浏览 8 评论 0原文

我听说使用 Stack 面板进行 UI 设计比 Grid 更容易推广。这里面有什么事实吗?我通常使用网格来设计我的 UI,最近在一份文档中我读到网格比堆栈面板消耗更多的时间来渲染;;所以我对此非常困惑..请给我更多有关此的信息..(WP7开发)

I heard that UI Design with Stack panel is more promotable that Grids. Is there any fact present in that. I am usually using Grid for Designing my UI, recently in a document i read that the Grid consumes more time for rendering rather than stack panel ;; so i am very much confused about this.. Please give me more informations about this.. (WP7 Development)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

那伤。 2024-10-29 00:05:05

在网格中,元素可以相对于彼此定位,通常可以自由移动(如果开发人员愿意的话)。除非明确指定,否则 Grid 不会强制执行特定定位。在 StackPanel 中,控件显然是堆叠的。因此,如果在 Grid 中,您将在单个序列中添加两个控件,那么它们将重叠。在 StackPanel 中,控件将被一个接一个地放置,无论是水平还是垂直。

通常,在 GridStackPanel 之间进行选择时不会产生性能开销。网格控件的一个好处是可以显式定义行和列,这最终可以创建更复杂的布局。每种都有其自己的位置,并且通常不可互换。

In a Grid, elements can be positioned relatively to each-other, being free to generally move around (if the developer wants to do so). A Grid doesn't enforce specific positioning unless explicitly specified. In a StackPanel the controls are obviously, stacked. So if in a Grid you would add two controls in a single sequence, those will be overlapping. In a StackPanel, the controls will be placed one after another, be it horizontally or vertically.

Generally, there is no performance overhead when it comes to choosing between Grid or StackPanel. A benefit of the Grid control is that there is a possibility to explicitly define rows and colums, which ultimately leads to the possibility of creating more complex layouts. Each has its place and are generally not interchangeable.

蓝眼泪 2024-10-29 00:05:05

Grid 和 Stackpanel 各有其位置,具体取决于您的 UI 要求。听起来你正在过早地优化。

我会实现最适合需要的面板,然后再担心性能(如果这是一个问题)。

Grid and Stackpanel each have their place it depends on your UI requirements. Sounds like you are prematurely optimizing.

I would implement the panel that most suits the need and then worry about performance later, if it is an issue.

单身情人 2024-10-29 00:05:05

从最近的经验来看,列表框是最好使用的容器类。主要优点是速度,因为它在内部使用虚拟化堆栈面板。

我尝试了网格面板和堆栈面板,两者都花费 25 秒来显示 60 个用户控件。在我切换到列表框后,这个时间下降到了 10 秒。

如果您需要额外的定位,请在每个列表项模板内使用网格。

Speaking from recent experience, a listbox is the best container class to use. The main benefit is speed as it uses a virtualizing stack panel internally.

I tried both a grid and a stack panel and both were taking 25 seconds to display 60 user controls. This dropped down to 10 seconds after I switched to the listbox.

If you needed the extra positioning, use a grid inside each list item template.

背叛残局 2024-10-29 00:05:05

只是想评论 SteveChadbourne,但不知道该怎么做。

请参阅http://www.codeproject.com/KB/showcase/WP7-Performance。 aspx (MonthCalendar) 是一个包含 126 个元素的网格示例,加载时间大约为 2 秒。如果你说你的60控件在25秒内加载,那么这不是使用的容器的问题,而是你的控件的问题。

当然,在这种情况下,UI 虚拟化会有所帮助。但总的来说,Grid 和 StackPanel 之间应该没有什么重要区别。网格应该慢一点,但差异无法衡量。

还有更重要的事情需要优化 - 模板、绑定等。上述文章描述了随后导致 MonthCalendar 控件速度提高 5 倍的优化步骤。高级 Silverlight 工具的效率如此低下,程序员常常感到惊讶。

Just wanted to comment SteveChadbourne, but don't know how to do it.

See http://www.codeproject.com/KB/showcase/WP7-Performance.aspx (MonthCalendar) for an example of a grid with 126 elements that loads in roughly 2 secs. If you say that your 60 controls load in 25 secs, then it is not the question of the container used, but of your controls.

In such case, of course, UI virtualizing helps. But in general, there should be no important difference between the Grid and StackPanel. Grid should be a bit slower, but the difference won't be measurable.

There are more important things to optimize - templates, bindings etc. The above mentioned article describes the optimization steps that subsequently resulted in 5x faster MonthCalendar control. Programmers use to be surprised how inefficient are the advanced Silverlight tools.

星光不落少年眉 2024-10-29 00:05:05

网格可以选择指定行或列索引,以便可以相应地对元素进行排序。因此,如果您需要对页面元素进行更多自定义,请使用网格。否则堆栈面板就足够了。网格具有行定义和列定义,因此它具有比堆栈面板更多的对象。根据我的测试,我没有看到最终用户可以看到的任何性能差异

Grid has the option to specify row or column index so that the elements can be ordered accordingly.So if you need more customization over your page elements , go with grid.Otherwise stack panel is enough.Grid has row definitions and column definitions so it has more objects than stack panel.Up to my testing , I didn't see any performance difference that can be visible to end user

贱人配狗天长地久 2024-10-29 00:05:05

Grid 和 Stackpanel 是容器,因此它们包含多个子项。区别在于它们包含元素的方式。

网格中的元素以矩阵形式存储,或者可以说表格形式存储。您可以定义列定义和行定义,并且可以访问和存储特定行和列的元素。

但在 stackpanel 中,元素以堆栈格式存储,即一个接一个地存储。所以它可以是垂直的也可以是水平的。

因此,根据您的要求,您可以满足其中大部分要求。

Grid and Stackpanel are containers so they contain multiple children items. The difference is the way they contain elements.

Elements in Grid are stored in matrix form or you can say tabular form. You can define columndefinitions and rowdefinitions and you can access and store element at a particular row and column.

But in stackpanel, elements are stored in stack format .i.e. one after other. so it may be either vertical or horizontal.

so Based on your requirements, you can make most of these requirements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文