Skip to content

Commit

Permalink
fix: Restore ability to have empty control template
Browse files Browse the repository at this point in the history
  • Loading branch information
dr1rrb committed Jun 1, 2021
1 parent f9b2a5b commit 55b18a8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/Control/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ internal View TemplatedRoot
get { return _templatedRoot; }
set
{
if (_templatedRoot == value)
{
return;
}

CleanupView(_templatedRoot);

UnregisterSubView();
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/FrameworkTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public FrameworkTemplate(object? owner, FrameworkTemplateBuilder? factory)
/// instance that has been detached from its parent may be reused at any time.
/// If a control needs to be the owner of a created instance, it needs to use <see cref="LoadContent"/>.
/// </remarks>
internal View LoadContentCached() => FrameworkTemplatePool.Instance.DequeueTemplate(this);
internal View? LoadContentCached() => FrameworkTemplatePool.Instance.DequeueTemplate(this);

/// <summary>
/// Manually return an unused template root created by <see cref="LoadContentCached"/> to the pool.
Expand Down
8 changes: 4 additions & 4 deletions src/Uno.UI/UI/Xaml/FrameworkTemplatePool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ private void Scavenge(bool isManual)
/// normally you shouldn't need to call this method. It may be useful in advanced memory management scenarios.</remarks>
public static void Scavenge() => Instance.Scavenge(true);

internal View DequeueTemplate(FrameworkTemplate template)
internal View? DequeueTemplate(FrameworkTemplate template)
{
var list = GetTemplatePool(template);

View instance;
View? instance;

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

instance = template.LoadContent() ?? new Grid();
instance = template.LoadContent();

if (IsPoolingEnabled && instance is IFrameworkElement)
{
Expand All @@ -208,7 +208,7 @@ internal View DequeueTemplate(FrameworkTemplate template)
}

#if USE_HARD_REFERENCES
if (IsPoolingEnabled)
if (IsPoolingEnabled && instance is {})
{
_activeInstances.Add(instance);
}
Expand Down

0 comments on commit 55b18a8

Please sign in to comment.