Browse Source

Support default binding mode on direct properties.

pull/429/head
Steven Kirk 11 years ago
parent
commit
8233f4df18
  1. 6
      src/Perspex.Base/DirectProperty.cs
  2. 7
      src/Perspex.Base/PerspexProperty.cs
  3. 6
      tests/Perspex.Base.UnitTests/DirectPropertyTests.cs

6
src/Perspex.Base/DirectProperty.cs

@ -24,11 +24,13 @@ namespace Perspex
/// <param name="name">The name of the property.</param>
/// <param name="getter">Gets the current value of the property.</param>
/// <param name="setter">Sets the value of the property. May be null.</param>
/// <param name="metadata">The property metadata.</param>
public DirectProperty(
string name,
Func<TOwner, TValue> getter,
Action<TOwner, TValue> setter = null)
: base(name, typeof(TOwner), new PropertyMetadata())
Action<TOwner, TValue> setter,
PropertyMetadata metadata)
: base(name, typeof(TOwner), metadata)
{
Contract.Requires<ArgumentNullException>(getter != null);

7
src/Perspex.Base/PerspexProperty.cs

@ -342,16 +342,19 @@ namespace Perspex
/// <param name="name">The name of the property.</param>
/// <param name="getter">Gets the current value of the property.</param>
/// <param name="setter">Sets the value of the property.</param>
/// <param name="defaultBindingMode">The default binding mode for the property.</param>
/// <returns>A <see cref="PerspexProperty{TValue}"/></returns>
public static DirectProperty<TOwner, TValue> RegisterDirect<TOwner, TValue>(
string name,
Func<TOwner, TValue> getter,
Action<TOwner, TValue> setter = null)
Action<TOwner, TValue> setter = null,
BindingMode defaultBindingMode = BindingMode.OneWay)
where TOwner : IPerspexObject
{
Contract.Requires<ArgumentNullException>(name != null);
var result = new DirectProperty<TOwner, TValue>(name, getter, setter);
var metadata = new PropertyMetadata(defaultBindingMode);
var result = new DirectProperty<TOwner, TValue>(name, getter, setter, metadata);
PerspexPropertyRegistry.Instance.Register(typeof(TOwner), result);
return result;
}

6
tests/Perspex.Base.UnitTests/DirectPropertyTests.cs

@ -30,7 +30,11 @@ namespace Perspex.Base.UnitTests
[Fact]
public void IsDirect_Property_Returns_True()
{
var target = new DirectProperty<Class1, string>("test", o => null);
var target = new DirectProperty<Class1, string>(
"test",
o => null,
null,
new PropertyMetadata());
Assert.True(target.IsDirect);
}

Loading…
Cancel
Save