Explain DependencyObject GetValue method

Multi tool use
Explain DependencyObject GetValue method
I am trying to understand value resolution method of Dependency Property.
when I look into GetValue method of DependencyObject, I see it is calling
return GetValueEntry(
LookupEntry(dp.GlobalIndex),
dp,
null,
RequestFlags.FullyResolved).Value;
Please refer to https://referencesource.microsoft.com/#windowsbase/Base/System/Windows/DependencyObject.cs,f4481c3e6cb032a5
Inside GetValueEntry method I found following block of code -
if (entryIndex.Found)
{
if ((requests & RequestFlags.RawEntry) != 0)
{
entry = _effectiveValues[entryIndex.Index];
}
else
{
entry = GetEffectiveValue(
entryIndex,
dp,
requests);
}
}
Please refer to
https://referencesource.microsoft.com/#windowsbase/Base/System/Windows/DependencyObject.cs,f4481c3e6cb032a5
As per my understanding, this block of code is getting executed when the corresponding DependencyObject has an entry for the Dependency Property in EffectiveValues array, then this block of code is getting executed.
Now following is the definition
internal enum RequestFlags
{
FullyResolved = 0x00,
AnimationBaseValue = 0x01,
CoercionBaseValue = 0x02,
DeferredReferences = 0x04,
SkipDefault = 0x08,
RawEntry = 0x10,
}
so (requests & RequestFlags.RawEntry) would always be 0 as we are passing RequestFlags.FullyResolved from GetValue. So that means, always GetEffectiveValue
get called.
Am I missing something? when do we get the value from _effectiveValues[entryIndex.Index]?
Also, I can see the following line of code
else if (!dp.IsDefaultValueChanged)
{
return EffectiveValueEntry.CreateDefaultValueEntry(dp, dp.DefaultMetadata.DefaultValue);
}
How can we change the default value of an existing Dependency Property?
And why this is being checked within Get operation?
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Not sure why you're doing these investigations, but if you just want to change the default value of a dependency property in a class derived from the one that declares the property, use OverrideMetadata.
– Clemens
Jun 30 at 20:29