From 7e954c6f05b115f48e0dd9c0d1a65094b34f2299 Mon Sep 17 00:00:00 2001 From: Vignesh-SF3580 <102575140+Vignesh-SF3580@users.noreply.github.com> Date: Thu, 11 Sep 2025 16:27:36 +0530 Subject: [PATCH 1/5] Update ViewExtensions.cs --- src/Core/src/Platform/Android/ViewExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/src/Platform/Android/ViewExtensions.cs b/src/Core/src/Platform/Android/ViewExtensions.cs index d65345bc4159..aa8746c53c76 100644 --- a/src/Core/src/Platform/Android/ViewExtensions.cs +++ b/src/Core/src/Platform/Android/ViewExtensions.cs @@ -597,7 +597,7 @@ internal static IDisposable OnLoaded(this View view, Action action) disposable?.Dispose(); disposable = null; - action(); + view.Post(action); }; view.ViewAttachedToWindow += routedEventHandler; From 456d854e7e624d74fe0872bc214b4fadf758bea5 Mon Sep 17 00:00:00 2001 From: Vignesh-SF3580 <102575140+Vignesh-SF3580@users.noreply.github.com> Date: Fri, 12 Sep 2025 12:05:16 +0530 Subject: [PATCH 2/5] Added testcase. --- .../TestCases.HostApp/Issues/Issue14364.cs | 50 +++++++++++++++++++ .../Tests/Issues/Issue14364.cs | 22 ++++++++ 2 files changed, 72 insertions(+) create mode 100644 src/Controls/tests/TestCases.HostApp/Issues/Issue14364.cs create mode 100644 src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue14364.cs diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue14364.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue14364.cs new file mode 100644 index 000000000000..803bad4a0262 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue14364.cs @@ -0,0 +1,50 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 14364, "Control size properties are not available during Loaded event", PlatformAffected.Android)] +public class Issue14364 : Shell +{ + public Issue14364() + { + ShellContent shellContent = new ShellContent + { + ContentTemplate = new DataTemplate(typeof(Issue14364Page)), + Route = "Issue14364Page" + }; + + Items.Add(shellContent); + } +} + +public class Issue14364Page : ContentPage +{ + public Issue14364Page() + { + var grid = new Grid + { + HeightRequest = 300, + WidthRequest = 200 + }; + + var label = new Label + { + Text = "Size", + AutomationId = "labelSize" + }; + + label.Loaded += Label_Loaded; + + grid.Children.Add(label); + Content = grid; + } + + private void Label_Loaded(object sender, EventArgs e) + { + if (sender is Label label) + { + var h1 = label.Height; + var h2 = label.Width; + + label.Text = $"Height: {h1}, Width: {h2}"; + } + } +} diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue14364.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue14364.cs new file mode 100644 index 000000000000..5ee05d881e08 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue14364.cs @@ -0,0 +1,22 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue14364 : _IssuesUITest +{ + public Issue14364(TestDevice testDevice) : base(testDevice) + { + } + + public override string Issue => "Control size properties are not available during Loaded event"; + + [Test] + [Category(UITestCategories.Layout)] + public void SizePropertiesAvailableDuringLoadedEvent() + { + var label = App.WaitForElement("labelSize"); + Assert.That(label.GetText(), Is.Not.EqualTo("Height: -1, Width: -1")); + } +} \ No newline at end of file From 1fa3bfedecc3493521cfcef40b78822b646dc663 Mon Sep 17 00:00:00 2001 From: Vignesh-SF3580 <102575140+Vignesh-SF3580@users.noreply.github.com> Date: Fri, 12 Sep 2025 12:26:56 +0530 Subject: [PATCH 3/5] Update Issue14364.cs --- src/Controls/tests/TestCases.HostApp/Issues/Issue14364.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue14364.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue14364.cs index 803bad4a0262..62a449b327b7 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/Issue14364.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue14364.cs @@ -37,7 +37,7 @@ public Issue14364Page() Content = grid; } - private void Label_Loaded(object sender, EventArgs e) + void Label_Loaded(object sender, EventArgs e) { if (sender is Label label) { From 2f3b470f8c8b13ef1399c90ffb3a7e9c1dd047bc Mon Sep 17 00:00:00 2001 From: Vignesh-SF3580 <102575140+Vignesh-SF3580@users.noreply.github.com> Date: Tue, 21 Oct 2025 16:10:34 +0530 Subject: [PATCH 4/5] Update ViewExtensions.cs --- src/Core/src/Platform/Android/ViewExtensions.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Core/src/Platform/Android/ViewExtensions.cs b/src/Core/src/Platform/Android/ViewExtensions.cs index aa8746c53c76..c0498665115f 100644 --- a/src/Core/src/Platform/Android/ViewExtensions.cs +++ b/src/Core/src/Platform/Android/ViewExtensions.cs @@ -597,7 +597,13 @@ internal static IDisposable OnLoaded(this View view, Action action) disposable?.Dispose(); disposable = null; - view.Post(action); + view.Post(() => + { + if (view.IsAttachedToWindow) + { + action(); + } + }); }; view.ViewAttachedToWindow += routedEventHandler; From 58db172e16553b20f737db99875dd3da736e8771 Mon Sep 17 00:00:00 2001 From: Vignesh-SF3580 <102575140+Vignesh-SF3580@users.noreply.github.com> Date: Fri, 20 Feb 2026 15:51:07 +0530 Subject: [PATCH 5/5] Update ViewExtensions.cs --- src/Core/src/Platform/Android/ViewExtensions.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Core/src/Platform/Android/ViewExtensions.cs b/src/Core/src/Platform/Android/ViewExtensions.cs index c0498665115f..a4517a872d5c 100644 --- a/src/Core/src/Platform/Android/ViewExtensions.cs +++ b/src/Core/src/Platform/Android/ViewExtensions.cs @@ -595,13 +595,15 @@ internal static IDisposable OnLoaded(this View view, Action action) return; } - disposable?.Dispose(); + // Store local reference to allow cancellation inside the Post callback + var localDisposable = disposable; disposable = null; view.Post(() => { - if (view.IsAttachedToWindow) + if (view.IsAttachedToWindow && localDisposable is not null) { action(); + localDisposable.Dispose(); } }); };