Browse Source

Tidy up API.

pull/3258/head
Steven Kirk 7 years ago
parent
commit
b8717bf6dc
  1. 56
      src/Avalonia.Base/AvaloniaObject.cs
  2. 189
      src/Avalonia.Base/AvaloniaObjectExtensions.cs
  3. 5
      src/Avalonia.Base/AvaloniaProperty`1.cs
  4. 10
      src/Avalonia.Base/DirectPropertyBase.cs
  5. 48
      src/Avalonia.Base/IAvaloniaObject.cs
  6. 6
      src/Avalonia.Base/StyledPropertyBase.cs
  7. 5
      tests/Avalonia.Base.UnitTests/AvaloniaPropertyTests.cs
  8. 12
      tests/Avalonia.Markup.UnitTests/Data/BindingTests_TemplatedParent.cs
  9. 40
      tests/Avalonia.Styling.UnitTests/SelectorTests_Child.cs
  10. 40
      tests/Avalonia.Styling.UnitTests/SelectorTests_Descendent.cs
  11. 12
      tests/Avalonia.Styling.UnitTests/SetterTests.cs
  12. 40
      tests/Avalonia.Styling.UnitTests/TestControlBase.cs
  13. 40
      tests/Avalonia.Styling.UnitTests/TestTemplatedControl.cs

56
src/Avalonia.Base/AvaloniaObject.cs

@ -9,7 +9,6 @@ using Avalonia.Diagnostics;
using Avalonia.Logging; using Avalonia.Logging;
using Avalonia.PropertyStore; using Avalonia.PropertyStore;
using Avalonia.Threading; using Avalonia.Threading;
using Avalonia.Utilities;
namespace Avalonia namespace Avalonia
{ {
@ -136,7 +135,8 @@ namespace Avalonia
/// <param name="property">The property.</param> /// <param name="property">The property.</param>
public void ClearValue(AvaloniaProperty property) public void ClearValue(AvaloniaProperty property)
{ {
Contract.Requires<ArgumentNullException>(property != null); property = property ?? throw new ArgumentNullException(nameof(property));
property.RouteClearValue(this); property.RouteClearValue(this);
} }
@ -146,24 +146,47 @@ namespace Avalonia
/// <param name="property">The property.</param> /// <param name="property">The property.</param>
public void ClearValue<T>(AvaloniaProperty<T> property) public void ClearValue<T>(AvaloniaProperty<T> property)
{ {
property = property ?? throw new ArgumentNullException(nameof(property));
VerifyAccess(); VerifyAccess();
switch (property) switch (property)
{ {
case StyledPropertyBase<T> styled: case StyledPropertyBase<T> styled:
_values.ClearLocalValue(styled); ClearValue(styled);
break; break;
case DirectPropertyBase<T> direct: case DirectPropertyBase<T> direct:
var p = AvaloniaPropertyRegistry.Instance.GetRegisteredDirect(this, direct); ClearValue(direct);
p.InvokeSetter(this, p.GetUnsetValue(GetType()));
break; break;
case null:
throw new ArgumentNullException(nameof(property));
default: default:
throw new NotSupportedException("Unsupported AvaloniaProperty type."); throw new NotSupportedException("Unsupported AvaloniaProperty type.");
} }
} }
/// <summary>
/// Clears a <see cref="AvaloniaProperty"/>'s local value.
/// </summary>
/// <param name="property">The property.</param>
public void ClearValue<T>(StyledPropertyBase<T> property)
{
property = property ?? throw new ArgumentNullException(nameof(property));
VerifyAccess();
_values?.ClearLocalValue(property);
}
/// <summary>
/// Clears a <see cref="AvaloniaProperty"/>'s local value.
/// </summary>
/// <param name="property">The property.</param>
public void ClearValue<T>(DirectPropertyBase<T> property)
{
property = property ?? throw new ArgumentNullException(nameof(property));
VerifyAccess();
var p = AvaloniaPropertyRegistry.Instance.GetRegisteredDirect(this, property);
p.InvokeSetter(this, p.GetUnsetValue(GetType()));
}
/// <summary> /// <summary>
/// Compares two objects using reference equality. /// Compares two objects using reference equality.
/// </summary> /// </summary>
@ -202,6 +225,8 @@ namespace Avalonia
/// <returns>The value.</returns> /// <returns>The value.</returns>
public object GetValue(AvaloniaProperty property) public object GetValue(AvaloniaProperty property)
{ {
property = property ?? throw new ArgumentNullException(nameof(property));
return property.RouteGetValue(this); return property.RouteGetValue(this);
} }
@ -213,11 +238,12 @@ namespace Avalonia
/// <returns>The value.</returns> /// <returns>The value.</returns>
public T GetValue<T>(AvaloniaProperty<T> property) public T GetValue<T>(AvaloniaProperty<T> property)
{ {
property = property ?? throw new ArgumentNullException(nameof(property));
return property switch return property switch
{ {
StyledPropertyBase<T> styled => GetValue(styled), StyledPropertyBase<T> styled => GetValue(styled),
DirectPropertyBase<T> direct => GetValue(direct), DirectPropertyBase<T> direct => GetValue(direct),
null => throw new ArgumentNullException(nameof(property)),
_ => throw new NotSupportedException("Unsupported AvaloniaProperty type.") _ => throw new NotSupportedException("Unsupported AvaloniaProperty type.")
}; };
} }
@ -292,6 +318,8 @@ namespace Avalonia
object value, object value,
BindingPriority priority = BindingPriority.LocalValue) BindingPriority priority = BindingPriority.LocalValue)
{ {
property = property ?? throw new ArgumentNullException(nameof(property));
property.RouteSetValue(this, value, priority); property.RouteSetValue(this, value, priority);
} }
@ -307,6 +335,8 @@ namespace Avalonia
T value, T value,
BindingPriority priority = BindingPriority.LocalValue) BindingPriority priority = BindingPriority.LocalValue)
{ {
property = property ?? throw new ArgumentNullException(nameof(property));
switch (property) switch (property)
{ {
case StyledPropertyBase<T> styled: case StyledPropertyBase<T> styled:
@ -315,8 +345,6 @@ namespace Avalonia
case DirectPropertyBase<T> direct: case DirectPropertyBase<T> direct:
SetValue(direct, value); SetValue(direct, value);
break; break;
case null:
throw new ArgumentNullException(nameof(property));
default: default:
throw new NotSupportedException("Unsupported AvaloniaProperty type."); throw new NotSupportedException("Unsupported AvaloniaProperty type.");
} }
@ -386,6 +414,9 @@ namespace Avalonia
IObservable<BindingValue<object>> source, IObservable<BindingValue<object>> source,
BindingPriority priority = BindingPriority.LocalValue) BindingPriority priority = BindingPriority.LocalValue)
{ {
property = property ?? throw new ArgumentNullException(nameof(property));
source = source ?? throw new ArgumentNullException(nameof(source));
return property.RouteBind(this, source, priority); return property.RouteBind(this, source, priority);
} }
@ -404,11 +435,13 @@ namespace Avalonia
IObservable<BindingValue<T>> source, IObservable<BindingValue<T>> source,
BindingPriority priority = BindingPriority.LocalValue) BindingPriority priority = BindingPriority.LocalValue)
{ {
property = property ?? throw new ArgumentNullException(nameof(property));
source = source ?? throw new ArgumentNullException(nameof(source));
return property switch return property switch
{ {
StyledPropertyBase<T> styled => Bind(styled, source, priority), StyledPropertyBase<T> styled => Bind(styled, source, priority),
DirectPropertyBase<T> direct => Bind(direct, source), DirectPropertyBase<T> direct => Bind(direct, source),
null => throw new ArgumentNullException(nameof(property)),
_ => throw new NotSupportedException("Unsupported AvaloniaProperty type."), _ => throw new NotSupportedException("Unsupported AvaloniaProperty type."),
}; };
} }
@ -429,6 +462,7 @@ namespace Avalonia
BindingPriority priority = BindingPriority.LocalValue) BindingPriority priority = BindingPriority.LocalValue)
{ {
property = property ?? throw new ArgumentNullException(nameof(property)); property = property ?? throw new ArgumentNullException(nameof(property));
source = source ?? throw new ArgumentNullException(nameof(source));
VerifyAccess(); VerifyAccess();
return Values.AddBinding(property, source, priority); return Values.AddBinding(property, source, priority);

189
src/Avalonia.Base/AvaloniaObjectExtensions.cs

@ -125,7 +125,7 @@ namespace Avalonia
/// for the specified property. /// for the specified property.
/// </returns> /// </returns>
public static IObservable<AvaloniaPropertyChangedEventArgs> GetPropertyChangedObservable( public static IObservable<AvaloniaPropertyChangedEventArgs> GetPropertyChangedObservable(
this IAvaloniaObject o, this IAvaloniaObject o,
AvaloniaProperty property) AvaloniaProperty property)
{ {
Contract.Requires<ArgumentNullException>(o != null); Contract.Requires<ArgumentNullException>(o != null);
@ -236,6 +236,58 @@ namespace Avalonia
o.GetBindingObservable(property)); o.GetBindingObservable(property));
} }
/// <summary>
/// Binds a <see cref="AvaloniaProperty"/> to an observable.
/// </summary>
/// <param name="target">The object.</param>
/// <param name="property">The property.</param>
/// <param name="source">The observable.</param>
/// <param name="priority">The priority of the binding.</param>
/// <returns>
/// A disposable which can be used to terminate the binding.
/// </returns>
public static IDisposable Bind(
this IAvaloniaObject target,
AvaloniaProperty property,
IObservable<BindingValue<object>> source,
BindingPriority priority = BindingPriority.LocalValue)
{
target = target ?? throw new ArgumentNullException(nameof(target));
property = property ?? throw new ArgumentNullException(nameof(property));
source = source ?? throw new ArgumentNullException(nameof(source));
return property.RouteBind(target, source, priority);
}
/// <summary>
/// Binds a <see cref="AvaloniaProperty"/> to an observable.
/// </summary>
/// <typeparam name="T">The type of the property.</typeparam>
/// <param name="target">The object.</param>
/// <param name="property">The property.</param>
/// <param name="source">The observable.</param>
/// <param name="priority">The priority of the binding.</param>
/// <returns>
/// A disposable which can be used to terminate the binding.
/// </returns>
public static IDisposable Bind<T>(
this IAvaloniaObject target,
AvaloniaProperty<T> property,
IObservable<BindingValue<T>> source,
BindingPriority priority = BindingPriority.LocalValue)
{
target = target ?? throw new ArgumentNullException(nameof(target));
property = property ?? throw new ArgumentNullException(nameof(property));
source = source ?? throw new ArgumentNullException(nameof(source));
return property switch
{
StyledPropertyBase<T> styled => target.Bind(styled, source, priority),
DirectPropertyBase<T> direct => target.Bind(direct, source),
_ => throw new NotSupportedException("Unsupported AvaloniaProperty type."),
};
}
/// <summary> /// <summary>
/// Binds a <see cref="AvaloniaProperty"/> to an observable. /// Binds a <see cref="AvaloniaProperty"/> to an observable.
/// </summary> /// </summary>
@ -252,6 +304,10 @@ namespace Avalonia
IObservable<object> source, IObservable<object> source,
BindingPriority priority = BindingPriority.LocalValue) BindingPriority priority = BindingPriority.LocalValue)
{ {
target = target ?? throw new ArgumentNullException(nameof(target));
property = property ?? throw new ArgumentNullException(nameof(property));
source = source ?? throw new ArgumentNullException(nameof(source));
return target.Bind( return target.Bind(
property, property,
source.ToBindingValue(), source.ToBindingValue(),
@ -274,6 +330,10 @@ namespace Avalonia
IObservable<T> source, IObservable<T> source,
BindingPriority priority = BindingPriority.LocalValue) BindingPriority priority = BindingPriority.LocalValue)
{ {
target = target ?? throw new ArgumentNullException(nameof(target));
property = property ?? throw new ArgumentNullException(nameof(property));
source = source ?? throw new ArgumentNullException(nameof(source));
return target.Bind( return target.Bind(
property, property,
source.ToBindingValue(), source.ToBindingValue(),
@ -299,16 +359,16 @@ namespace Avalonia
IBinding binding, IBinding binding,
object anchor = null) object anchor = null)
{ {
Contract.Requires<ArgumentNullException>(target != null); target = target ?? throw new ArgumentNullException(nameof(target));
Contract.Requires<ArgumentNullException>(property != null); property = property ?? throw new ArgumentNullException(nameof(property));
Contract.Requires<ArgumentNullException>(binding != null); binding = binding ?? throw new ArgumentNullException(nameof(binding));
var metadata = property.GetMetadata(target.GetType()) as IDirectPropertyMetadata; var metadata = property.GetMetadata(target.GetType()) as IDirectPropertyMetadata;
var result = binding.Initiate( var result = binding.Initiate(
target, target,
property, property,
anchor, anchor,
metadata?.EnableDataValidation ?? false); metadata?.EnableDataValidation ?? false);
if (result != null) if (result != null)
@ -321,6 +381,125 @@ namespace Avalonia
} }
} }
/// <summary>
/// Clears a <see cref="AvaloniaProperty"/>'s local value.
/// </summary>
/// <param name="target">The object.</param>
/// <param name="property">The property.</param>
public static void ClearValue(this IAvaloniaObject target, AvaloniaProperty property)
{
target = target ?? throw new ArgumentNullException(nameof(target));
property = property ?? throw new ArgumentNullException(nameof(property));
property.RouteClearValue(target);
}
/// <summary>
/// Clears a <see cref="AvaloniaProperty"/>'s local value.
/// </summary>
/// <param name="target">The object.</param>
/// <param name="property">The property.</param>
public static void ClearValue<T>(this IAvaloniaObject target, AvaloniaProperty<T> property)
{
target = target ?? throw new ArgumentNullException(nameof(target));
property = property ?? throw new ArgumentNullException(nameof(property));
switch (property)
{
case StyledPropertyBase<T> styled:
target.ClearValue(styled);
break;
case DirectPropertyBase<T> direct:
target.ClearValue(direct);
break;
default:
throw new NotSupportedException("Unsupported AvaloniaProperty type.");
}
}
/// <summary>
/// Gets a <see cref="AvaloniaProperty"/> value.
/// </summary>
/// <param name="target">The object.</param>
/// <param name="property">The property.</param>
/// <returns>The value.</returns>
public static object GetValue(this IAvaloniaObject target, AvaloniaProperty property)
{
target = target ?? throw new ArgumentNullException(nameof(target));
property = property ?? throw new ArgumentNullException(nameof(property));
return property.RouteGetValue(target);
}
/// <summary>
/// Gets a <see cref="AvaloniaProperty"/> value.
/// </summary>
/// <typeparam name="T">The type of the property.</typeparam>
/// <param name="target">The object.</param>
/// <param name="property">The property.</param>
/// <returns>The value.</returns>
public static T GetValue<T>(this IAvaloniaObject target, AvaloniaProperty<T> property)
{
target = target ?? throw new ArgumentNullException(nameof(target));
property = property ?? throw new ArgumentNullException(nameof(property));
return property switch
{
StyledPropertyBase<T> styled => target.GetValue(styled),
DirectPropertyBase<T> direct => target.GetValue(direct),
_ => throw new NotSupportedException("Unsupported AvaloniaProperty type.")
};
}
/// <summary>
/// Sets a <see cref="AvaloniaProperty"/> value.
/// </summary>
/// <param name="target">The object.</param>
/// <param name="property">The property.</param>
/// <param name="value">The value.</param>
/// <param name="priority">The priority of the value.</param>
public static void SetValue(
this IAvaloniaObject target,
AvaloniaProperty property,
object value,
BindingPriority priority = BindingPriority.LocalValue)
{
target = target ?? throw new ArgumentNullException(nameof(target));
property = property ?? throw new ArgumentNullException(nameof(property));
property.RouteSetValue(target, value, priority);
}
/// <summary>
/// Sets a <see cref="AvaloniaProperty"/> value.
/// </summary>
/// <typeparam name="T">The type of the property.</typeparam>
/// <param name="target">The object.</param>
/// <param name="property">The property.</param>
/// <param name="value">The value.</param>
/// <param name="priority">The priority of the value.</param>
public static void SetValue<T>(
this IAvaloniaObject target,
AvaloniaProperty<T> property,
T value,
BindingPriority priority = BindingPriority.LocalValue)
{
target = target ?? throw new ArgumentNullException(nameof(target));
property = property ?? throw new ArgumentNullException(nameof(property));
switch (property)
{
case StyledPropertyBase<T> styled:
target.SetValue(styled, value, priority);
break;
case DirectPropertyBase<T> direct:
target.SetValue(direct, value);
break;
default:
throw new NotSupportedException("Unsupported AvaloniaProperty type.");
}
}
/// <summary> /// <summary>
/// Subscribes to a property changed notifications for changes that originate from a /// Subscribes to a property changed notifications for changes that originate from a
/// <typeparamref name="TTarget"/>. /// <typeparamref name="TTarget"/>.

5
src/Avalonia.Base/AvaloniaProperty`1.cs

@ -43,11 +43,6 @@ namespace Avalonia
{ {
} }
internal override void RouteClearValue(IAvaloniaObject o)
{
o.ClearValue<TValue>(this);
}
protected BindingValue<object> TryConvert(object value) protected BindingValue<object> TryConvert(object value)
{ {
if (value == UnsetValue) if (value == UnsetValue)

10
src/Avalonia.Base/DirectPropertyBase.cs

@ -116,6 +116,12 @@ namespace Avalonia
} }
} }
/// <inheritdoc/>
internal override void RouteClearValue(IAvaloniaObject o)
{
o.ClearValue<TValue>(this);
}
/// <inheritdoc/> /// <inheritdoc/>
internal override object? RouteGetValue(IAvaloniaObject o) internal override object? RouteGetValue(IAvaloniaObject o)
{ {
@ -132,7 +138,7 @@ namespace Avalonia
if (v.HasValue) if (v.HasValue)
{ {
o.SetValue<TValue>(this, (TValue)v.Value, priority); o.SetValue<TValue>(this, (TValue)v.Value);
} }
else if (v.Type == BindingValueType.UnsetValue) else if (v.Type == BindingValueType.UnsetValue)
{ {
@ -151,7 +157,7 @@ namespace Avalonia
BindingPriority priority) BindingPriority priority)
{ {
var adapter = TypedBindingAdapter<TValue>.Create(o, this, source); var adapter = TypedBindingAdapter<TValue>.Create(o, this, source);
return o.Bind<TValue>(this, adapter, priority); return o.Bind<TValue>(this, adapter);
} }
internal override void RouteInheritanceParentChanged(AvaloniaObject o, IAvaloniaObject oldParent) internal override void RouteInheritanceParentChanged(AvaloniaObject o, IAvaloniaObject oldParent)

48
src/Avalonia.Base/IAvaloniaObject.cs

@ -17,23 +17,24 @@ namespace Avalonia
event EventHandler<AvaloniaPropertyChangedEventArgs> PropertyChanged; event EventHandler<AvaloniaPropertyChangedEventArgs> PropertyChanged;
/// <summary> /// <summary>
/// Clears a <see cref="AvaloniaProperty"/>'s local value. /// Clears an <see cref="AvaloniaProperty"/>'s local value.
/// </summary> /// </summary>
/// <param name="property">The property.</param> /// <param name="property">The property.</param>
public void ClearValue(AvaloniaProperty property); void ClearValue<T>(StyledPropertyBase<T> property);
/// <summary> /// <summary>
/// Clears a <see cref="AvaloniaProperty"/>'s local value. /// Clears an <see cref="AvaloniaProperty"/>'s local value.
/// </summary> /// </summary>
/// <param name="property">The property.</param> /// <param name="property">The property.</param>
public void ClearValue<T>(AvaloniaProperty<T> property); void ClearValue<T>(DirectPropertyBase<T> property);
/// <summary> /// <summary>
/// Gets a <see cref="AvaloniaProperty"/> value. /// Gets a <see cref="AvaloniaProperty"/> value.
/// </summary> /// </summary>
/// <typeparam name="T">The type of the property.</typeparam>
/// <param name="property">The property.</param> /// <param name="property">The property.</param>
/// <returns>The value.</returns> /// <returns>The value.</returns>
object GetValue(AvaloniaProperty property); T GetValue<T>(StyledPropertyBase<T> property);
/// <summary> /// <summary>
/// Gets a <see cref="AvaloniaProperty"/> value. /// Gets a <see cref="AvaloniaProperty"/> value.
@ -41,7 +42,7 @@ namespace Avalonia
/// <typeparam name="T">The type of the property.</typeparam> /// <typeparam name="T">The type of the property.</typeparam>
/// <param name="property">The property.</param> /// <param name="property">The property.</param>
/// <returns>The value.</returns> /// <returns>The value.</returns>
T GetValue<T>(AvaloniaProperty<T> property); T GetValue<T>(DirectPropertyBase<T> property);
/// <summary> /// <summary>
/// Checks whether a <see cref="AvaloniaProperty"/> is animating. /// Checks whether a <see cref="AvaloniaProperty"/> is animating.
@ -60,12 +61,13 @@ namespace Avalonia
/// <summary> /// <summary>
/// Sets a <see cref="AvaloniaProperty"/> value. /// Sets a <see cref="AvaloniaProperty"/> value.
/// </summary> /// </summary>
/// <typeparam name="T">The type of the property.</typeparam>
/// <param name="property">The property.</param> /// <param name="property">The property.</param>
/// <param name="value">The value.</param> /// <param name="value">The value.</param>
/// <param name="priority">The priority of the value.</param> /// <param name="priority">The priority of the value.</param>
void SetValue( void SetValue<T>(
AvaloniaProperty property, StyledPropertyBase<T> property,
object value, T value,
BindingPriority priority = BindingPriority.LocalValue); BindingPriority priority = BindingPriority.LocalValue);
/// <summary> /// <summary>
@ -74,24 +76,21 @@ namespace Avalonia
/// <typeparam name="T">The type of the property.</typeparam> /// <typeparam name="T">The type of the property.</typeparam>
/// <param name="property">The property.</param> /// <param name="property">The property.</param>
/// <param name="value">The value.</param> /// <param name="value">The value.</param>
/// <param name="priority">The priority of the value.</param> void SetValue<T>(DirectPropertyBase<T> property, T value);
void SetValue<T>(
AvaloniaProperty<T> property,
T value,
BindingPriority priority = BindingPriority.LocalValue);
/// <summary> /// <summary>
/// Binds a <see cref="AvaloniaProperty"/> to an observable. /// Binds a <see cref="AvaloniaProperty"/> to an observable.
/// </summary> /// </summary>
/// <typeparam name="T">The type of the property.</typeparam>
/// <param name="property">The property.</param> /// <param name="property">The property.</param>
/// <param name="source">The observable.</param> /// <param name="source">The observable.</param>
/// <param name="priority">The priority of the binding.</param> /// <param name="priority">The priority of the binding.</param>
/// <returns> /// <returns>
/// A disposable which can be used to terminate the binding. /// A disposable which can be used to terminate the binding.
/// </returns> /// </returns>
IDisposable Bind( IDisposable Bind<T>(
AvaloniaProperty property, StyledPropertyBase<T> property,
IObservable<BindingValue<object>> source, IObservable<BindingValue<T>> source,
BindingPriority priority = BindingPriority.LocalValue); BindingPriority priority = BindingPriority.LocalValue);
/// <summary> /// <summary>
@ -100,14 +99,12 @@ namespace Avalonia
/// <typeparam name="T">The type of the property.</typeparam> /// <typeparam name="T">The type of the property.</typeparam>
/// <param name="property">The property.</param> /// <param name="property">The property.</param>
/// <param name="source">The observable.</param> /// <param name="source">The observable.</param>
/// <param name="priority">The priority of the binding.</param>
/// <returns> /// <returns>
/// A disposable which can be used to terminate the binding. /// A disposable which can be used to terminate the binding.
/// </returns> /// </returns>
IDisposable Bind<T>( IDisposable Bind<T>(
AvaloniaProperty<T> property, DirectPropertyBase<T> property,
IObservable<BindingValue<T>> source, IObservable<BindingValue<T>> source);
BindingPriority priority = BindingPriority.LocalValue);
/// <summary> /// <summary>
/// Registers an object as an inheritance child. /// Registers an object as an inheritance child.
@ -130,19 +127,14 @@ namespace Avalonia
/// </remarks> /// </remarks>
void RemoveInheritanceChild(IAvaloniaObject child); void RemoveInheritanceChild(IAvaloniaObject child);
//void InheritanceParentChanged<T>(
// StyledPropertyBase<T> property,
// IAvaloniaObject oldParent,
// IAvaloniaObject newParent);
/// <summary> /// <summary>
/// Called when an inheritable property changes on an object registered as an inheritance /// Called when an inheritable property changes on an object registered as an inheritance
/// parent. /// parent.
/// </summary> /// </summary>
/// <typeparam name="T">The type of the value.</typeparam> /// <typeparam name="T">The type of the value.</typeparam>
/// <param name="property">The property that has changed.</param> /// <param name="property">The property that has changed.</param>
/// <param name="oldValue">The old property value.</param> /// <param name="oldValue"></param>
/// <param name="newValue">The new property value.</param> /// <param name="newValue"></param>
void InheritedPropertyChanged<T>( void InheritedPropertyChanged<T>(
AvaloniaProperty<T> property, AvaloniaProperty<T> property,
Optional<T> oldValue, Optional<T> oldValue,

6
src/Avalonia.Base/StyledPropertyBase.cs

@ -153,6 +153,12 @@ namespace Avalonia
} }
} }
/// <inheritdoc/>
internal override void RouteClearValue(IAvaloniaObject o)
{
o.ClearValue<TValue>(this);
}
/// <inheritdoc/> /// <inheritdoc/>
internal override object RouteGetValue(IAvaloniaObject o) internal override object RouteGetValue(IAvaloniaObject o)
{ {

5
tests/Avalonia.Base.UnitTests/AvaloniaPropertyTests.cs

@ -154,6 +154,11 @@ namespace Avalonia.Base.UnitTests
throw new NotImplementedException(); throw new NotImplementedException();
} }
internal override void RouteClearValue(IAvaloniaObject o)
{
throw new NotImplementedException();
}
internal override object RouteGetValue(IAvaloniaObject o) internal override object RouteGetValue(IAvaloniaObject o)
{ {
throw new NotImplementedException(); throw new NotImplementedException();

12
tests/Avalonia.Markup.UnitTests/Data/BindingTests_TemplatedParent.cs

@ -35,8 +35,7 @@ namespace Avalonia.Markup.UnitTests.Data
target.Verify(x => x.Bind( target.Verify(x => x.Bind(
TextBox.TextProperty, TextBox.TextProperty,
It.IsAny<IObservable<BindingValue<object>>>(), It.IsAny<IObservable<BindingValue<string>>>()));
BindingPriority.TemplatedParent));
} }
[Fact] [Fact]
@ -55,8 +54,7 @@ namespace Avalonia.Markup.UnitTests.Data
target.Verify(x => x.Bind( target.Verify(x => x.Bind(
TextBox.TextProperty, TextBox.TextProperty,
It.IsAny<IObservable<BindingValue<object>>>(), It.IsAny<IObservable<BindingValue<string>>>()));
BindingPriority.TemplatedParent));
} }
private Mock<IControl> CreateTarget( private Mock<IControl> CreateTarget(
@ -66,9 +64,9 @@ namespace Avalonia.Markup.UnitTests.Data
var result = new Mock<IControl>(); var result = new Mock<IControl>();
result.Setup(x => x.GetValue(Control.TemplatedParentProperty)).Returns(templatedParent); result.Setup(x => x.GetValue(Control.TemplatedParentProperty)).Returns(templatedParent);
result.Setup(x => x.GetValue((AvaloniaProperty)Control.TemplatedParentProperty)).Returns(templatedParent); result.Setup(x => x.GetValue(Control.TemplatedParentProperty)).Returns(templatedParent);
result.Setup(x => x.GetValue((AvaloniaProperty)TextBox.TextProperty)).Returns(text); result.Setup(x => x.GetValue(TextBox.TextProperty)).Returns(text);
result.Setup(x => x.Bind(It.IsAny<AvaloniaProperty>(), It.IsAny<IObservable<BindingValue<object>>>(), It.IsAny<BindingPriority>())) result.Setup(x => x.Bind(It.IsAny<DirectPropertyBase<string>>(), It.IsAny<IObservable<BindingValue<string>>>()))
.Returns(Disposable.Empty); .Returns(Disposable.Empty);
return result; return result;
} }

40
tests/Avalonia.Styling.UnitTests/SelectorTests_Child.cs

@ -195,6 +195,46 @@ namespace Avalonia.Styling.UnitTests
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void ClearValue<T>(StyledPropertyBase<T> property)
{
throw new NotImplementedException();
}
public void ClearValue<T>(DirectPropertyBase<T> property)
{
throw new NotImplementedException();
}
public T GetValue<T>(StyledPropertyBase<T> property)
{
throw new NotImplementedException();
}
public T GetValue<T>(DirectPropertyBase<T> property)
{
throw new NotImplementedException();
}
public void SetValue<T>(StyledPropertyBase<T> property, T value, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public void SetValue<T>(DirectPropertyBase<T> property, T value)
{
throw new NotImplementedException();
}
public IDisposable Bind<T>(StyledPropertyBase<T> property, IObservable<BindingValue<T>> source, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public IDisposable Bind<T>(DirectPropertyBase<T> property, IObservable<BindingValue<T>> source)
{
throw new NotImplementedException();
}
} }
public class TestLogical1 : TestLogical public class TestLogical1 : TestLogical

40
tests/Avalonia.Styling.UnitTests/SelectorTests_Descendent.cs

@ -225,6 +225,46 @@ namespace Avalonia.Styling.UnitTests
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void ClearValue<T>(StyledPropertyBase<T> property)
{
throw new NotImplementedException();
}
public void ClearValue<T>(DirectPropertyBase<T> property)
{
throw new NotImplementedException();
}
public T GetValue<T>(StyledPropertyBase<T> property)
{
throw new NotImplementedException();
}
public T GetValue<T>(DirectPropertyBase<T> property)
{
throw new NotImplementedException();
}
public void SetValue<T>(StyledPropertyBase<T> property, T value, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public void SetValue<T>(DirectPropertyBase<T> property, T value)
{
throw new NotImplementedException();
}
public IDisposable Bind<T>(StyledPropertyBase<T> property, IObservable<BindingValue<T>> source, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public IDisposable Bind<T>(DirectPropertyBase<T> property, IObservable<BindingValue<T>> source)
{
throw new NotImplementedException();
}
} }
public class TestLogical1 : TestLogical public class TestLogical1 : TestLogical

12
tests/Avalonia.Styling.UnitTests/SetterTests.cs

@ -83,8 +83,7 @@ namespace Avalonia.Styling.UnitTests
control.Verify(x => x.Bind( control.Verify(x => x.Bind(
TextBlock.TextProperty, TextBlock.TextProperty,
It.IsAny<IObservable<BindingValue<object>>>(), It.IsAny<IObservable<BindingValue<string>>>()));
BindingPriority.Style));
} }
[Fact] [Fact]
@ -99,8 +98,7 @@ namespace Avalonia.Styling.UnitTests
control.Verify(x => x.Bind( control.Verify(x => x.Bind(
TextBlock.TextProperty, TextBlock.TextProperty,
It.IsAny<IObservable<BindingValue<object>>>(), It.IsAny<IObservable<BindingValue<string>>>()));
BindingPriority.StyleTrigger));
} }
[Fact] [Fact]
@ -114,8 +112,7 @@ namespace Avalonia.Styling.UnitTests
control.Verify(x => x.Bind( control.Verify(x => x.Bind(
TextBlock.TextProperty, TextBlock.TextProperty,
It.IsAny<IObservable<BindingValue<object>>>(), It.IsAny<IObservable<BindingValue<string>>>()));
BindingPriority.Style));
} }
[Fact] [Fact]
@ -130,8 +127,7 @@ namespace Avalonia.Styling.UnitTests
control.Verify(x => x.Bind( control.Verify(x => x.Bind(
TextBlock.TextProperty, TextBlock.TextProperty,
It.IsAny<IObservable<BindingValue<object>>>(), It.IsAny<IObservable<BindingValue<string>>>()));
BindingPriority.StyleTrigger));
} }
private IBinding CreateMockBinding(AvaloniaProperty property) private IBinding CreateMockBinding(AvaloniaProperty property)

40
tests/Avalonia.Styling.UnitTests/TestControlBase.cs

@ -109,5 +109,45 @@ namespace Avalonia.Styling.UnitTests
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void ClearValue<T>(StyledPropertyBase<T> property)
{
throw new NotImplementedException();
}
public void ClearValue<T>(DirectPropertyBase<T> property)
{
throw new NotImplementedException();
}
public T GetValue<T>(StyledPropertyBase<T> property)
{
throw new NotImplementedException();
}
public T GetValue<T>(DirectPropertyBase<T> property)
{
throw new NotImplementedException();
}
public void SetValue<T>(StyledPropertyBase<T> property, T value, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public void SetValue<T>(DirectPropertyBase<T> property, T value)
{
throw new NotImplementedException();
}
public IDisposable Bind<T>(StyledPropertyBase<T> property, IObservable<BindingValue<T>> source, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public IDisposable Bind<T>(DirectPropertyBase<T> property, IObservable<BindingValue<T>> source)
{
throw new NotImplementedException();
}
} }
} }

40
tests/Avalonia.Styling.UnitTests/TestTemplatedControl.cs

@ -107,5 +107,45 @@ namespace Avalonia.Styling.UnitTests
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void ClearValue<T>(StyledPropertyBase<T> property)
{
throw new NotImplementedException();
}
public void ClearValue<T>(DirectPropertyBase<T> property)
{
throw new NotImplementedException();
}
public T GetValue<T>(StyledPropertyBase<T> property)
{
throw new NotImplementedException();
}
public T GetValue<T>(DirectPropertyBase<T> property)
{
throw new NotImplementedException();
}
public void SetValue<T>(StyledPropertyBase<T> property, T value, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public void SetValue<T>(DirectPropertyBase<T> property, T value)
{
throw new NotImplementedException();
}
public IDisposable Bind<T>(StyledPropertyBase<T> property, IObservable<BindingValue<T>> source, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public IDisposable Bind<T>(DirectPropertyBase<T> property, IObservable<BindingValue<T>> source)
{
throw new NotImplementedException();
}
} }
} }

Loading…
Cancel
Save