From 5dd3a3456c32752ef3617ad8c10bce1ed668f77f Mon Sep 17 00:00:00 2001 From: Carl de Billy Date: Mon, 18 Jan 2021 22:59:43 -0500 Subject: [PATCH] feat(dependecyproperty): Implemented this.RegisterDefaultValueProvider() --- .../UI/Xaml/DependencyObjectStore.Binder.cs | 2 +- .../DependencyPropertyDetailsCollection.cs | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Uno.UI/UI/Xaml/DependencyObjectStore.Binder.cs b/src/Uno.UI/UI/Xaml/DependencyObjectStore.Binder.cs index 2de22d75ba57..942ec2aa04c8 100644 --- a/src/Uno.UI/UI/Xaml/DependencyObjectStore.Binder.cs +++ b/src/Uno.UI/UI/Xaml/DependencyObjectStore.Binder.cs @@ -472,7 +472,7 @@ internal void SetBindingValue(DependencyPropertyDetails propertyDetails, object internal void RegisterDefaultValueProvider(DefaultValueProvider provider) { - + _properties.RegisterDefaultValueProvider(provider); } /// diff --git a/src/Uno.UI/UI/Xaml/DependencyPropertyDetailsCollection.cs b/src/Uno.UI/UI/Xaml/DependencyPropertyDetailsCollection.cs index 8588bd36fd78..ac4f58ee4abe 100644 --- a/src/Uno.UI/UI/Xaml/DependencyPropertyDetailsCollection.cs +++ b/src/Uno.UI/UI/Xaml/DependencyPropertyDetailsCollection.cs @@ -38,6 +38,7 @@ partial class DependencyPropertyDetailsCollection : IDisposable private int _entriesLength; private int _minId; private int _maxId; + private DependencyObjectStore.DefaultValueProvider? _defaultValueProvider; /// /// Creates an instance using the specified DependencyObject @@ -114,6 +115,11 @@ public DependencyPropertyDetails FindPropertyDetails(DependencyProperty property if (forceCreate && propertyEntry == null) { propertyEntry = new DependencyPropertyDetails(property, _ownerType); + + if(_defaultValueProvider != null && _defaultValueProvider(property, out var v)) + { + propertyEntry.SetValue(v, DependencyPropertyValuePrecedences.DefaultValue); + } } return propertyEntry; @@ -146,7 +152,13 @@ public DependencyPropertyDetails FindPropertyDetails(DependencyProperty property } ref var propertyEntry = ref _entries![property.UniqueId - _minId]; - return propertyEntry = new DependencyPropertyDetails(property, _ownerType); + propertyEntry = new DependencyPropertyDetails(property, _ownerType); + if (_defaultValueProvider != null && _defaultValueProvider(property, out var v)) + { + propertyEntry.SetValue(v, DependencyPropertyValuePrecedences.DefaultValue); + } + + return propertyEntry; } else { @@ -176,5 +188,10 @@ private void ReturnEntriesToPool() } internal IEnumerable GetAllDetails() => _entries.Trim(); + + public void RegisterDefaultValueProvider(DependencyObjectStore.DefaultValueProvider provider) + { + _defaultValueProvider = provider; + } } }