Skip to content

Commit

Permalink
feat(dependecyproperty): Implemented this.RegisterDefaultValueProvider()
Browse files Browse the repository at this point in the history
  • Loading branch information
carldebilly committed Feb 25, 2021
1 parent 91408f4 commit 5dd3a34
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/DependencyObjectStore.Binder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ internal void SetBindingValue(DependencyPropertyDetails propertyDetails, object

internal void RegisterDefaultValueProvider(DefaultValueProvider provider)
{

_properties.RegisterDefaultValueProvider(provider);
}

/// <summary>
Expand Down
19 changes: 18 additions & 1 deletion src/Uno.UI/UI/Xaml/DependencyPropertyDetailsCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ partial class DependencyPropertyDetailsCollection : IDisposable
private int _entriesLength;
private int _minId;
private int _maxId;
private DependencyObjectStore.DefaultValueProvider? _defaultValueProvider;

/// <summary>
/// Creates an instance using the specified DependencyObject <see cref="Type"/>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -176,5 +188,10 @@ private void ReturnEntriesToPool()
}

internal IEnumerable<DependencyPropertyDetails> GetAllDetails() => _entries.Trim();

public void RegisterDefaultValueProvider(DependencyObjectStore.DefaultValueProvider provider)
{
_defaultValueProvider = provider;
}
}
}

0 comments on commit 5dd3a34

Please sign in to comment.