Skip to content

Conversation

lindexi
Copy link
Member

@lindexi lindexi commented May 30, 2022

Fixes #6627

Description

We should call FindResourceInEnviroment when the PrefetchedValue is the DependencyProperty.UnsetValue.

private object TryProvideValueImpl(IServiceProvider serviceProvider, bool allowDeferredReference, bool mustReturnDeferredResourceReference)
{
// Get prefetchedValue
DeferredResourceReference prefetchedValue = PrefetchedValue;
object value;
if (prefetchedValue == null)
{
// Do a normal look up.
value = FindResourceInEnviroment(serviceProvider, allowDeferredReference, mustReturnDeferredResourceReference);
}
else
{
// If we have a Deferred Value, first check the current parse stack for a better (nearer)
// value. This happens when this is a parse of deferred content and there is another
// Resource Dictionary availible above this, yet still part of this deferred content.
// This searches up to the outer most enclosing resource dictionary.
value = FindResourceInDeferredContent(serviceProvider, allowDeferredReference, mustReturnDeferredResourceReference);
// If we didn't find a new value in this part of deferred content
// then use the existing prefetchedValue (DeferredResourceReference)
if (value == DependencyProperty.UnsetValue)
{
value = allowDeferredReference
? prefetchedValue
: prefetchedValue.GetValue(BaseValueSourceInternal.Unknown);
}
}
return value;
}

Customer Impact

We can use this feature to reduce duplicate creation of resources.

Regression

None.

Testing

CI and my demo: https://github.com/lindexi/lindexi_gd/tree/cd70c10df4f57fdedd9d2fbee018290e432422cf/GeacejalcurnawLarjearemwhear

And I cherry-pick the commit to build the test version in dotnet-campus/DotNetCampus.CustomWpf#9

Risk

Changed the resource lookup behavior

Microsoft Reviewers: Open in CodeFlow

@lindexi lindexi requested a review from a team as a code owner May 30, 2022 06:21
@ghost ghost assigned lindexi May 30, 2022
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label May 30, 2022
@ghost ghost requested review from SamBent, dipeshmsft and singhashish-wpf May 30, 2022 06:21
@ghost ghost added the Community Contribution A label for all community Contributions label May 30, 2022
@lindexi lindexi changed the title Return null when the PrefetchedValue is the UnsetValue. Fix StaticResourceExtension will not find the resources of the ResourceDictionary of the sibling node May 30, 2022
@lindexi lindexi closed this Jun 13, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jul 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The StaticResourceExtension will not find the resources of the ResourceDictionary of the sibling node

1 participant