Skip to content

Commit 55b18a8

Browse files
committed
fix: Restore ability to have empty control template
1 parent f9b2a5b commit 55b18a8

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ internal View TemplatedRoot
147147
get { return _templatedRoot; }
148148
set
149149
{
150+
if (_templatedRoot == value)
151+
{
152+
return;
153+
}
154+
150155
CleanupView(_templatedRoot);
151156

152157
UnregisterSubView();

src/Uno.UI/UI/Xaml/FrameworkTemplate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public FrameworkTemplate(object? owner, FrameworkTemplateBuilder? factory)
7070
/// instance that has been detached from its parent may be reused at any time.
7171
/// If a control needs to be the owner of a created instance, it needs to use <see cref="LoadContent"/>.
7272
/// </remarks>
73-
internal View LoadContentCached() => FrameworkTemplatePool.Instance.DequeueTemplate(this);
73+
internal View? LoadContentCached() => FrameworkTemplatePool.Instance.DequeueTemplate(this);
7474

7575
/// <summary>
7676
/// Manually return an unused template root created by <see cref="LoadContentCached"/> to the pool.

src/Uno.UI/UI/Xaml/FrameworkTemplatePool.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ private void Scavenge(bool isManual)
165165
/// normally you shouldn't need to call this method. It may be useful in advanced memory management scenarios.</remarks>
166166
public static void Scavenge() => Instance.Scavenge(true);
167167

168-
internal View DequeueTemplate(FrameworkTemplate template)
168+
internal View? DequeueTemplate(FrameworkTemplate template)
169169
{
170170
var list = GetTemplatePool(template);
171171

172-
View instance;
172+
View? instance;
173173

174174
if (list.Count == 0)
175175
{
@@ -183,7 +183,7 @@ internal View DequeueTemplate(FrameworkTemplate template)
183183
this.Log().Debug($"Creating new template, id={GetTemplateDebugId(template)} IsPoolingEnabled:{IsPoolingEnabled}");
184184
}
185185

186-
instance = template.LoadContent() ?? new Grid();
186+
instance = template.LoadContent();
187187

188188
if (IsPoolingEnabled && instance is IFrameworkElement)
189189
{
@@ -208,7 +208,7 @@ internal View DequeueTemplate(FrameworkTemplate template)
208208
}
209209

210210
#if USE_HARD_REFERENCES
211-
if (IsPoolingEnabled)
211+
if (IsPoolingEnabled && instance is {})
212212
{
213213
_activeInstances.Add(instance);
214214
}

0 commit comments

Comments
 (0)