Skip to content

Commit 640a543

Browse files
committed
perf: Improve DependencyPropertyDetails performance
1 parent e84146f commit 640a543

File tree

3 files changed

+261
-58
lines changed

3 files changed

+261
-58
lines changed

src/Uno.UI.Tests/DependencyProperty/Given_DependencyProperty.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,13 @@ public void When_Set_With_Both_Style_And_LocalValue()
16441644
#endif
16451645
}
16461646

1647+
[TestMethod]
1648+
public void When_DefaultValueOverride()
1649+
{
1650+
var SUT = new MyDependencyObjectWithDefaultValueOverride();
1651+
Assert.AreEqual(42, SUT.GetValue(MyDependencyObjectWithDefaultValueOverride.MyPropertyProperty));
1652+
}
1653+
16471654
private class MyDependencyObject : FrameworkElement
16481655
{
16491656
internal static readonly DependencyProperty PropAProperty = DependencyProperty.Register(
@@ -1790,5 +1797,38 @@ private void OnMyNullableChanged(DependencyPropertyChangedEventArgs e)
17901797

17911798
}
17921799

1800+
partial class MyDependencyObjectWithDefaultValueOverride : DependencyObject
1801+
{
1802+
public MyDependencyObjectWithDefaultValueOverride()
1803+
{
1804+
this.RegisterDefaultValueProvider(OnProvideDefaultValue);
1805+
}
1806+
1807+
private bool OnProvideDefaultValue(DependencyProperty property, out object defaultValue)
1808+
{
1809+
if(property == MyPropertyProperty)
1810+
{
1811+
defaultValue = 42;
1812+
1813+
return true;
1814+
}
1815+
1816+
defaultValue = null;
1817+
return false;
1818+
}
1819+
1820+
public int MyProperty
1821+
{
1822+
get { return (int)GetValue(MyPropertyProperty); }
1823+
set { SetValue(MyPropertyProperty, value); }
1824+
}
1825+
1826+
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
1827+
public static readonly DependencyProperty MyPropertyProperty =
1828+
DependencyProperty.Register("MyProperty", typeof(int), typeof(MyDependencyObjectWithDefaultValueOverride), new PropertyMetadata(0));
1829+
1830+
}
1831+
1832+
17931833
#endregion
17941834
}

0 commit comments

Comments
 (0)