Page.Width = -1 in Page_Loaded() in Mac Catalyst Maui
Description
Create a new ContentPage and hookup the Page_OnLoaded and Page_OnSizeChanged event. You will see this.Width equals to -1 in both Page_OnLoaded() and Page_OnSizeChanged events if running on a Mac Catalyst. The same code works fine (this.Width returns the actual width) on Windows, the same code works partially fine (it returns the correct width in OnSizeChanged event but not OnLoaded event, see #10747) on Android, I didn't have a chance to test it on iOS.
It has the same issue for a ContentView as well.
Steps to Reproduce
Run the linked repo and you will see 2 exceptions got thrown. One is thrown in OnLoaded event and the other is thrown in SizeChanged event. Neither of the exceptions are thrown if running on Windows, only 1 exception will be thrown on Android.
Link to public reproduction project repository
https://github.com/bymin/MauiLayoutIssueOnMac.git
Version with bug
7.0 Release Candidate 1
Last version that worked well
Unknown/Other
Affected platforms
macOS
Affected platform versions
MacOS 12.6, VS 2022 on Mac Preview 17.4. build 2285, Xcode 14.0.1
Did you find any workaround?
If you remove the <Grid></Grid> from the xaml and put the <button> directly under Content page, it will then not throw exception in SizeChanged event, but still throws exception in OnLoaded event.
Relevant log output
No response
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
We have this issues as well.
Verified this issue with Visual Studio Enterprise 17.8.0 Preview 1.0(.NET8). Can repro on android platform with sample project.
MauiLayoutIssueOnMac-main.zip
Things won't be guarunteed to be measured in PageLoaded You need to use SizeChanged
Hi @bymin. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.