Skip to content

Commit 8ad591f

Browse files
committed
fix: Adjust ContentPresenter automatic propagation
Conditionally disables TemplatedParent propagation when the TemplatedParent itself is already in the visual tree.
1 parent 3c6f7c5 commit 8ad591f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ContentControl.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ public void Init()
6161
_testsResources = new TestsResources();
6262
}
6363

64+
[TestMethod]
65+
[RunsOnUIThread]
66+
[DataRow(typeof(Grid))]
67+
[DataRow(typeof(StackPanel))]
68+
[DataRow(typeof(Border))]
69+
[DataRow(typeof(ContentPresenter))]
70+
public async Task When_SelfLoading(Type type)
71+
{
72+
var control = (FrameworkElement)Activator.CreateInstance(type);
73+
74+
control.Width = 200;
75+
control.Height = 200;
76+
77+
await UITestHelper.Load(control);
78+
}
79+
6480
[TestMethod]
6581
public async Task When_Binding_Within_Control_Template()
6682
{

src/Uno.UI/UI/Xaml/Controls/ContentPresenter/ContentPresenter.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,9 @@ protected override void OnApplyTemplate()
662662
#if ANDROID || __IOS__
663663
&& this is not NativeCommandBarPresenter // Uno specific: NativeCommandBarPresenter breaks if you inherit from the TP
664664
#endif
665+
// Uno Specific: Workaround to avoid creating a circular reference when TemplatedParent
666+
// is incorrectly inherited. See https://github.com/unoplatform/uno/issues/17470.
667+
&& !pTemplatedParent.IsLoaded
665668
)
666669
{
667670
// bool needsRefresh = false;

0 commit comments

Comments
 (0)