Browse Source

Moved Bind method to IPerspexObject.

Allow IPerspexObject to be bound to an IBinding.
pull/396/head
Steven Kirk 10 years ago
parent
commit
444ca577ca
  1. 30
      src/Perspex.Base/PerspexObjectExtensions.cs
  2. 30
      src/Perspex.Controls/ControlExtensions.cs
  3. 13
      src/Perspex.Styling/Styling/Setter.cs

30
src/Perspex.Base/PerspexObjectExtensions.cs

@ -164,6 +164,36 @@ namespace Perspex
return result;
}
/// <summary>
/// Binds a property on an <see cref="IPerspexObject"/> to an <see cref="IBinding"/>.
/// </summary>
/// <param name="o">The object.</param>
/// <param name="property">The property to bind.</param>
/// <param name="binding">The binding.</param>
/// <returns>An <see cref="IDisposable"/> which can be used to cancel the binding.</returns>
public static IDisposable Bind(
this IPerspexObject o,
PerspexProperty property,
IBinding binding)
{
Contract.Requires<ArgumentNullException>(o != null);
Contract.Requires<ArgumentNullException>(property != null);
Contract.Requires<ArgumentNullException>(binding != null);
var mode = binding.Mode;
if (mode == BindingMode.Default)
{
mode = property.DefaultBindingMode;
}
return o.Bind(
property,
binding.CreateSubject(o, property),
mode,
binding.Priority);
}
/// <summary>
/// Binds a property to a subject according to a <see cref="BindingMode"/>.
/// </summary>

30
src/Perspex.Controls/ControlExtensions.cs

@ -14,36 +14,6 @@ namespace Perspex.Controls
/// </summary>
public static class ControlExtensions
{
/// <summary>
/// Binds a property on an <see cref="IControl"/> to an <see cref="IBinding"/>.
/// </summary>
/// <param name="o">The object.</param>
/// <param name="property">The property to bind.</param>
/// <param name="binding">The binding.</param>
/// <returns>An <see cref="IDisposable"/> which can be used to cancel the binding.</returns>
public static IDisposable Bind(
this IControl o,
PerspexProperty property,
IBinding binding)
{
Contract.Requires<ArgumentNullException>(o != null);
Contract.Requires<ArgumentNullException>(property != null);
Contract.Requires<ArgumentNullException>(binding != null);
var mode = binding.Mode;
if (mode == BindingMode.Default)
{
mode = property.DefaultBindingMode;
}
return o.Bind(
property,
binding.CreateSubject(o, property),
mode,
binding.Priority);
}
/// <summary>
/// Tries to being the control into view.
/// </summary>

13
src/Perspex.Styling/Styling/Setter.cs

@ -79,7 +79,7 @@ namespace Perspex.Styling
{
if (activator == null)
{
Bind(control, Property, binding);
control.Bind(Property, binding);
}
else
{
@ -102,15 +102,10 @@ namespace Perspex.Styling
}
}
private void Bind(IStyleable control, PerspexProperty property, IBinding binding)
{
Bind(control, property, binding, binding.CreateSubject(control, property));
}
private void Bind(
IStyleable control,
PerspexProperty property,
IBinding binding,
IStyleable control,
PerspexProperty property,
IBinding binding,
ISubject<object> subject)
{
var mode = binding.Mode;

Loading…
Cancel
Save