Skip to content

Commit

Permalink
fix(resources): Don't update static resources on loading
Browse files Browse the repository at this point in the history
Fix bug where static resources could be incorrectly re-resolved on loading into the visual tree. This was manifesting exclusively in the case that hot reload was active (ie in debug, but not release).
  • Loading branch information
davidjohnoliver committed Jan 25, 2022
1 parent b9effad commit 1d927dc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Data/BindingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static void UpdateResourceBindings(this DependencyObject instance)
if(instance is IDependencyObjectStoreProvider provider)
{
provider.Store.ApplyElementNameBindings();
provider.Store.UpdateResourceBindings(ResourceUpdateReason.StaticResourceLoading);
provider.Store.UpdateResourceBindings(ResourceUpdateReason.ResolvedOnLoading);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/Uno.UI/UI/Xaml/Data/ResourceUpdateReason.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@ internal enum ResourceUpdateReason
/// Updates that should be propagated recursively through the visual tree
/// </summary>
PropagatesThroughTree = ThemeResource | HotReload,
/// <summary>
/// Updates that should be re-resolved when the bound object or its parent is loaded into the visual tree
/// </summary>
ResolvedOnLoading = StaticResourceLoading | ThemeResource,
}
}
8 changes: 7 additions & 1 deletion src/Uno.UI/UI/Xaml/DependencyObjectStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,12 @@ private void InnerUpdateResourceBindings(ResourceUpdateReason updateReason, Reso
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void InnerUpdateResourceBindingsUnsafe(ResourceUpdateReason updateReason, ResourceDictionary[] dictionariesInScope, DependencyProperty property, ResourceBinding binding)
{
if ((binding.UpdateReason & updateReason) == ResourceUpdateReason.None)
{
// If the reason for the update doesn't match the reason(s) that the binding was created for, don't update it
return;
}

var wasSet = false;
foreach (var dict in dictionariesInScope)
{
Expand All @@ -1253,7 +1259,7 @@ private void InnerUpdateResourceBindingsUnsafe(ResourceUpdateReason updateReason
}
}

if (!wasSet && (binding.UpdateReason & updateReason) != ResourceUpdateReason.None)
if (!wasSet)
{
if (ResourceResolver.TryTopLevelRetrieval(binding.ResourceKey, binding.ParseContext, out var value))
{
Expand Down

0 comments on commit 1d927dc

Please sign in to comment.