From 8ad591fc9e5a18c162207f28b85de5d69a60b396 Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Wed, 18 Sep 2024 22:53:36 -0400 Subject: [PATCH] fix: Adjust ContentPresenter automatic propagation Conditionally disables TemplatedParent propagation when the TemplatedParent itself is already in the visual tree. --- .../Given_ContentControl.cs | 16 ++++++++++++++++ .../ContentPresenter/ContentPresenter.cs | 3 +++ 2 files changed, 19 insertions(+) diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ContentControl.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ContentControl.cs index ca4652e19172..5e8e9c518121 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ContentControl.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ContentControl.cs @@ -61,6 +61,22 @@ public void Init() _testsResources = new TestsResources(); } + [TestMethod] + [RunsOnUIThread] + [DataRow(typeof(Grid))] + [DataRow(typeof(StackPanel))] + [DataRow(typeof(Border))] + [DataRow(typeof(ContentPresenter))] + public async Task When_SelfLoading(Type type) + { + var control = (FrameworkElement)Activator.CreateInstance(type); + + control.Width = 200; + control.Height = 200; + + await UITestHelper.Load(control); + } + [TestMethod] public async Task When_Binding_Within_Control_Template() { diff --git a/src/Uno.UI/UI/Xaml/Controls/ContentPresenter/ContentPresenter.cs b/src/Uno.UI/UI/Xaml/Controls/ContentPresenter/ContentPresenter.cs index 843ace98a889..45827d30caec 100644 --- a/src/Uno.UI/UI/Xaml/Controls/ContentPresenter/ContentPresenter.cs +++ b/src/Uno.UI/UI/Xaml/Controls/ContentPresenter/ContentPresenter.cs @@ -662,6 +662,9 @@ protected override void OnApplyTemplate() #if ANDROID || __IOS__ && this is not NativeCommandBarPresenter // Uno specific: NativeCommandBarPresenter breaks if you inherit from the TP #endif + // Uno Specific: Workaround to avoid creating a circular reference when TemplatedParent + // is incorrectly inherited. See https://github.com/unoplatform/uno/issues/17470. + && !pTemplatedParent.IsLoaded ) { // bool needsRefresh = false;