Browse Source

Update binding anchor to be plain object.

Because e.g. a Style can be an anchor but is not an IPerspexObject.
pull/464/head
Steven Kirk 11 years ago
parent
commit
66bd84f22c
  1. 15
      src/Markup/Perspex.Markup.Xaml/Data/Binding.cs
  2. 28
      src/Markup/Perspex.Markup.Xaml/Data/MultiBinding.cs
  3. 12
      src/Markup/Perspex.Markup.Xaml/Data/StyleResourceBinding.cs
  4. 12
      src/Perspex.Base/Data/IBinding.cs

15
src/Markup/Perspex.Markup.Xaml/Data/Binding.cs

@ -61,20 +61,11 @@ namespace Perspex.Markup.Xaml.Data
/// </summary>
public object Source { get; set; }
/// <summary>
/// Creates a subject that can be used to get and set the value of the binding.
/// </summary>
/// <param name="target">The target instance.</param>
/// <param name="targetProperty">The target property. May be null.</param>
/// <param name="treeAnchor">
/// For `ElementName` bindings to elements that are not themselves controls, describes
/// where in the logical tree to begin searching for the named element.
/// </param>
/// <returns>An <see cref="ISubject{Object}"/>.</returns>
/// <inheritdoc/>
public ISubject<object> CreateSubject(
IPerspexObject target,
PerspexProperty targetProperty,
IPerspexObject treeAnchor = null)
object anchor = null)
{
Contract.Requires<ArgumentNullException>(target != null);
@ -86,7 +77,7 @@ namespace Perspex.Markup.Xaml.Data
if (pathInfo.ElementName != null || ElementName != null)
{
observer = CreateElementObserver(
(target as IControl) ?? (treeAnchor as IControl),
(target as IControl) ?? (anchor as IControl),
pathInfo.ElementName ?? ElementName,
pathInfo.Path);
}

28
src/Markup/Perspex.Markup.Xaml/Data/MultiBinding.cs

@ -49,35 +49,11 @@ namespace Perspex.Markup.Xaml.Data
/// </summary>
public RelativeSource RelativeSource { get; set; }
/// <summary>
/// Applies the binding to a property on an instance.
/// </summary>
/// <param name="instance">The target instance.</param>
/// <param name="property">The target property.</param>
public void Bind(IPerspexObject instance, PerspexProperty property)
{
var subject = CreateSubject(instance, property);
if (subject != null)
{
Bind(instance, property, subject);
}
}
/// <summary>
/// Creates a subject that can be used to get and set the value of the binding.
/// </summary>
/// <param name="target">The target instance.</param>
/// <param name="targetProperty">The target property. May be null.</param>
/// <param name="treeAnchor">
/// For `ElementName` bindings to elements that are not themselves controls, describes
/// where in the logical tree to begin searching for the named element.
/// </param>
/// <returns>An <see cref="ISubject{Object}"/>.</returns>
/// <inheritdoc/>
public ISubject<object> CreateSubject(
IPerspexObject target,
PerspexProperty targetProperty,
IPerspexObject treeAnchor = null)
object anchor = null)
{
if (Converter == null)
{

12
src/Markup/Perspex.Markup.Xaml/Data/StyleResourceBinding.cs

@ -37,22 +37,22 @@ namespace Perspex.Markup.Xaml.Data
public ISubject<object> CreateSubject(
IPerspexObject target,
PerspexProperty targetProperty,
IPerspexObject treeAnchor = null)
object anchor = null)
{
return new Subject(target, Name, treeAnchor);
return new Subject(target, Name, anchor);
}
private class Subject : ISubject<object>
{
private IPerspexObject _target;
private string _name;
private IPerspexObject _treeAnchor;
private object _anchor;
public Subject(IPerspexObject target, string name, IPerspexObject treeAnchor)
public Subject(IPerspexObject target, string name, object anchor)
{
_target = target;
_name = name;
_treeAnchor = treeAnchor;
this._anchor = anchor;
}
public void OnCompleted()
@ -69,7 +69,7 @@ namespace Perspex.Markup.Xaml.Data
public IDisposable Subscribe(IObserver<object> observer)
{
var host = (_target as IControl) ?? (_treeAnchor as IControl);
var host = (_target as IControl) ?? (_anchor as IControl);
if (host != null)
{

12
src/Perspex.Base/Data/IBinding.cs

@ -25,14 +25,16 @@ namespace Perspex.Data
/// </summary>
/// <param name="target">The target instance.</param>
/// <param name="targetProperty">The target property. May be null.</param>
/// <param name="treeAnchor">
/// For `ElementName` bindings to elements that are not themselves controls, describes
/// where in the logical tree to begin searching for the named element.
/// </param>
/// <param name="anchor">An optional anchor from which to locate required context.</param>
/// <returns>An <see cref="ISubject{Object}"/>.</returns>
/// <remarks>
/// When binding to objects that are not in the logical tree, certain types of binding need
/// an anchor into the tree in order to locate named controls or resources. The
/// <paramref name="anchor"/> parameter can be used to provice this context.
/// </remarks>
ISubject<object> CreateSubject(
IPerspexObject target,
PerspexProperty targetProperty,
IPerspexObject treeAnchor = null);
object anchor = null);
}
}

Loading…
Cancel
Save