admin管理员组文章数量:1122832
As far as I've worked with MAUI, I have only ever been using <VerticalStackLayout/>
and <HorizontalStackLayout/>
to position child elements horizontally or vertically.
I rarely or pretty much never use <StackLayout/>
as I read it might perform slightly worse.
When, if at all, is it recommended to use <StackLayout/>
and adjust its Orientation
attribute?
Should I use...
<StackLayout Orientation="Horizontal">
<StackLayout/>
<StackLayout Orientation="Vertical">
<StackLayout/>
...instead of...
<HorizontalStackLayout>
<HorizontalStackLayout/>
<VerticalStackLayout>
<VerticalStackLayout/>
...or the other way around, depending on different scenarios?
As far as I've worked with MAUI, I have only ever been using <VerticalStackLayout/>
and <HorizontalStackLayout/>
to position child elements horizontally or vertically.
I rarely or pretty much never use <StackLayout/>
as I read it might perform slightly worse.
When, if at all, is it recommended to use <StackLayout/>
and adjust its Orientation
attribute?
Should I use...
<StackLayout Orientation="Horizontal">
<StackLayout/>
<StackLayout Orientation="Vertical">
<StackLayout/>
...instead of...
<HorizontalStackLayout>
<HorizontalStackLayout/>
<VerticalStackLayout>
<VerticalStackLayout/>
...or the other way around, depending on different scenarios?
Share Improve this question edited Nov 21, 2024 at 15:22 Al John asked Nov 21, 2024 at 15:05 Al JohnAl John 8708 silver badges36 bronze badges 2 |1 Answer
Reset to default 1From a GitHub issue on MAUI (https://github.com/dotnet/maui/issues/6766) there is a simple explanation for performance on how the StackLayout
will work compared to the HorizontalStackLayout
and VerticalStackLayout
.
The simplest way to look at it would be to stick to this:
If you know the orientation of the layout will not change then use
HorizontalStackLayout
orVerticalStackLayout
depending on the orientation you need.If you need to change the orientation and it might change at runtime then use
StackLayout
E.G.<StackLayout Orientation="{Binding MyStackOrientation}">
Since Xamarin Forms only had StackLayout
, porting apps to MAUI is relatively easy as the code does not have to change, so also helps for backward compatibility - developers don't have to go around all their XAML updating their stack layouts.
The official docs also mention StackLayout
being less performant though there is no explanation. https://learn.microsoft.com/en-us/dotnet/maui/user-interface/layouts/horizontalstacklayout?view=net-maui-8.0
本文标签: performanceWhich StackLayout type should I use in MAUIStack Overflow
版权声明:本文标题:performance - Which StackLayout type should I use in MAUI? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736309608a1934079.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
StackLayout
is just a facade left in place for backward compatibility. I don't think there is any performance difference, although for future proofing its probably better to stop using it – Jason Commented Nov 21, 2024 at 15:18