With a grid, i can say that i want one element to take up 3/4 of the page and one to take up 1/3 of the page by using width = "3*" and width = "1*"
使用网格,我可以说我希望一个元素占据页面的3/4,一个占用页面的1/3,使用width =“3 *”和width =“1 *”
Is it possible to do the same with Stackpanels? Or is the only way to do it by placing the stackpanels inside a grid?
Stackpanels可以做同样的事情吗?或者是通过将堆叠面板放在网格中来实现它的唯一方法?
1 个解决方案
#1
In the .NET Framework, there are a number of different Panel
classes. Some of them like the Grid
and DockPanel
provide resizing capabilities that resize the Panel
children, while others don't. Generally, the ones that provide this functionality have a cost in terms of CPU and/or RAM.
在.NET Framework中,有许多不同的Panel类。其中一些像Grid和DockPanel提供了调整Panel子项大小的调整大小功能,而其他人没有。通常,提供此功能的那些在CPU和/或RAM方面具有成本。
Therefore, when requiring a Panel
for simple layout purposes, these Panel
types should be avoided and a simple StackPanel
should be used instead. Other times, we require this extra functionality and so we should use one of these more expensive Panel
s.
因此,当需要Panel进行简单布局时,应避免使用这些Panel类型,而应使用简单的StackPanel。其他时候,我们需要这个额外的功能,所以我们应该使用这些更昂贵的面板之一。
Please see the Panels Overview page on MSDN for a much fuller description of the .NET Panel
s.
有关.NET面板的更全面描述,请参阅MSDN上的“面板概述”页面。
So, to actually answer your question(s), no, a StackPanel
cannot use similar sizing capabilities as the Grid
and you can't do what you want even if you place StackPanel
s inside a Grid
because although the Grid
's cells may change size when the parent is resized, the StackPanel
s contained within will not.
因此,为了实际回答你的问题,不,StackPanel不能使用与网格类似的大小调整功能,即使你将StackPanels放在网格内也无法做你想要的事情,因为尽管Grid的单元格可能会改变大小。父级调整大小,其中包含的StackPanels不会。
#1
In the .NET Framework, there are a number of different Panel
classes. Some of them like the Grid
and DockPanel
provide resizing capabilities that resize the Panel
children, while others don't. Generally, the ones that provide this functionality have a cost in terms of CPU and/or RAM.
在.NET Framework中,有许多不同的Panel类。其中一些像Grid和DockPanel提供了调整Panel子项大小的调整大小功能,而其他人没有。通常,提供此功能的那些在CPU和/或RAM方面具有成本。
Therefore, when requiring a Panel
for simple layout purposes, these Panel
types should be avoided and a simple StackPanel
should be used instead. Other times, we require this extra functionality and so we should use one of these more expensive Panel
s.
因此,当需要Panel进行简单布局时,应避免使用这些Panel类型,而应使用简单的StackPanel。其他时候,我们需要这个额外的功能,所以我们应该使用这些更昂贵的面板之一。
Please see the Panels Overview page on MSDN for a much fuller description of the .NET Panel
s.
有关.NET面板的更全面描述,请参阅MSDN上的“面板概述”页面。
So, to actually answer your question(s), no, a StackPanel
cannot use similar sizing capabilities as the Grid
and you can't do what you want even if you place StackPanel
s inside a Grid
because although the Grid
's cells may change size when the parent is resized, the StackPanel
s contained within will not.
因此,为了实际回答你的问题,不,StackPanel不能使用与网格类似的大小调整功能,即使你将StackPanels放在网格内也无法做你想要的事情,因为尽管Grid的单元格可能会改变大小。父级调整大小,其中包含的StackPanels不会。