Browse Source

Add IBinding2 support to observable bind overloads.

In the case of `TemplateBinding`, the `IObservable<object?>` bind overload is selected by C#. Add an explicit check for an `IBinding2` here to use the more performant code-path.
pull/13970/head
Steven Kirk 3 years ago
parent
commit
92638a9bdd
  1. 22
      src/Avalonia.Base/AvaloniaObject.cs

22
src/Avalonia.Base/AvaloniaObject.cs

@ -455,7 +455,16 @@ namespace Avalonia
VerifyAccess();
ValidatePriority(priority);
return _values.AddBinding(property, source, priority);
if (source is IBinding2 b)
{
if (b.Instance(this, property, null) is not UntypedBindingExpressionBase expression)
throw new NotSupportedException("Binding returned unsupported IBindingExpression.");
return GetValueStore().AddBinding(property, expression);
}
else
{
return _values.AddBinding(property, source, priority);
}
}
/// <summary>
@ -527,7 +536,16 @@ namespace Avalonia
throw new ArgumentException($"The property {property.Name} is readonly.");
}
return _values.AddBinding(property, source);
if (source is IBinding2 b)
{
if (b.Instance(this, property, null) is not UntypedBindingExpressionBase expression)
throw new NotSupportedException("Binding returned unsupported IBindingExpression.");
return GetValueStore().AddBinding(property, expression);
}
else
{
return _values.AddBinding(property, source);
}
}
/// <summary>

Loading…
Cancel
Save