[MAUI-Windows] Unhandled layout cycle exception occurs when setting "IsVisible = False" inside FlexLayout
See original GitHub issueDescription
I am trying to add a view (say Grid) inside a FlexLayout. After added the view, when I set “IsVisible” property of the grid at the run time. I am facing the below unhandled exception
Exception: “A cycle occurred while laying out the GUI.” Message: “Layout cycle detected. Layout could not complete.”

Note: This occurs with all kind of MAUI views inside a FlexLayout.
Steps to Reproduce
- Create a new MAUI App.
- Add a view (say grid) inside the flex layout.
- Use a switch control to to toggle the visibility of the view at the run time.
- Run the sample.
- Disable the view at the run time by setting its property “IsVisible=false”. Now the unhandled Exception will be thrown.
I have attached a sample to reproduce the issue. MauiApp1.zip
Run the attached sample and toggle the switch control “Make Visible”, in the left top of the app.
Version with bug
6.0.419
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
Windows SDK 10.0.19041
Did you find any workaround?
No
Relevant log output
No logs obtained due to unhandled exception occurs.
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:9 (1 by maintainers)
Top Results From Across the Web
FlexLayout isn't displaying the bindable data in .NET Maui?
This is a known problem in FlexLayout. It has nothing to do with bindable data. I wrote a simple demo based on your...
Read more >I'm getting an exception error Layout cycle detected
I am developing my application on a parralels virtual machine, not sure if this is the problem. .NET MAUI.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m having similar issues that started today after updating VS 2022 to 17.3 and VS2022 Preview to 17.4.
My steps to reproduce is that I have a FlexLayout on a ContentPage and if I add anything to it then I get the error. If I comment out the FlexLayout or it’s contents then no error.
It’s been working fine until the latest Visual Studio updates. Not sure which version of Windows SDK I was on before but I’m on 10.0.19041 now.
I have installed the latest 7.0.49 version and my app is still crashing as before. I first thought that the bug has not been fixed. But then I noticed that the error message is different and that it crashes after the update even if I remove the flex layout. I have downloaded the repro project from this issue, and tried it with the latest .net6 and .net7 version, and it works without crashing.
So yes, this bug has been fixed but it was replaced by another one that crashes the app in different more general situations. If I have time, I will try to find the problem, create a repro project and file a new issue for it. It seems that MAUI on .NET 7 have problem with some lazily-loaded views (even without flex layout) that used to work in Xamarin.Forms and older versions of MAUI. When a lazily-loaded view should be loaded and the LazyView.Content is set to the newly created view, the app crashes:
This is a Windows-only problem. It works on Android. I will investigate it more and file a new issue.