question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stacklayout leaves layout space for items whose IsVisible=false

See original GitHub issue

Description

Given the following Stacklayout with three buttons, I’d expect that if one of the buttons was marked isvisible=false, that the layout would not reserve layout space in the stacklayout for the invisible button. (that’s the case in Xamarin Forms). However, MAUI appears to generate a layout for a button that’s not visible.

<StackLayout Orientation="Horizontal">
                <Button Margin="10,0" Text="Button 1" HorizontalOptions="FillAndExpand" />
                <Button Margin="10,0" Text="Button 2" HorizontalOptions="FillAndExpand" />
                <Button Margin="10,0" Text="Button 3" HorizontalOptions="FillAndExpand" IsVisible="False" />
            </StackLayout>

image

Steps to Reproduce

  1. Create a File -> New MAUI project
  2. Create a horizontal stacklayout with three buttons
  3. mark one button’s isvisible as false
  4. Expected result would be the two remaining visible buttons that stretch the width of the Stacklayout
  5. Actual result is that the invisible button still is laid out and has reserved space.

Link to public reproduction project repository

https://github.com/edgiardina/StackLayout_IsVisible_Bug

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android

Affected platform versions

all platforms

Did you find any workaround?

No workaround I can see

Relevant log output

No response

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
edgiardinacommented, Nov 27, 2022

@nebula2 Sure, I could, in the Page codebehind, do the math manually. That makes it more of a pain to restyle later. But the main point is that this worked for the most part in Xamarin Forms. Why is there a departure here in MAUI? Why are layout options considered “cursed” yet available to use?

It’s been a frustrating road unfortunately in my attempt to migrate a small hobby project from Xamarin Forms to MAUI (definitely over 50 hours now for the migration, if not more). The layout engine seems to have under the covers been subtly changed such that stacklayouts are not really usable. Stacklayouts were IMHO a great solution to the fragmentation of mobile display sizes. declaring discrete widths/heights and calculating my own layouts instead of using XAML goes against the spirit of the x-plat project. It wouldn’t be so bad to change all the stacklayouts to grids if we didn’t already have the Xamarin Forms standard to see how it should work, vs how MAUI works.

There have been a lot of confusing design decisions for MAUI that have made switching painful and I don’t understand the underlying philosophy behind them. Why is MAUI tied to the .net workflow version and not a nuget package like forms? The mobile frameworks shift quickly as vendors change them, and waiting until .NET releases in november isn’t an option IMHO. Why did stacklayouts get nerfed in MAUI?

1reaction
nebula2commented, Nov 27, 2022

@edgiardina I don’t know 😕 I struggled very hard to create a stable app using MAUI (with lots of experience using Xamarin) and I have collected quite an amount of workarounds…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Xamarin Forms IsVisible false taking up space
I set the view (or the StackLayout) to be isVisible=false and the HeightRequest=0 so that it should not take up space and should...
Read more >
Stack Layout IsVisible property - Microsoft Q&A
Hi, I have a StackLayout and it is changing its visibility from false to true. But initially the layout is not visible even...
Read more >
Create a Custom Layout in Xamarin.Forms
This will ensure that the custom layout won't leave space for invisible children.
Read more >
Stop doing IsVisible=“true/false” to Show/Hide Views in ...
When developing UI a common use case is to hide/show a View according to a certain condition, when thinking on how to do...
Read more >
Scrolling is not persisting the new position inside a ...
You can use the IsVisible property to completely hide/show an element. For example: < ActivityIndicator IsVisible = "False" />.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found