From 66bd84f22cd7484a54513074a41124f9f422273e Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 25 Feb 2016 20:02:23 +0100 Subject: [PATCH] Update binding anchor to be plain object. Because e.g. a Style can be an anchor but is not an IPerspexObject. --- .../Perspex.Markup.Xaml/Data/Binding.cs | 15 ++-------- .../Perspex.Markup.Xaml/Data/MultiBinding.cs | 28 ++----------------- .../Data/StyleResourceBinding.cs | 12 ++++---- src/Perspex.Base/Data/IBinding.cs | 12 ++++---- 4 files changed, 18 insertions(+), 49 deletions(-) diff --git a/src/Markup/Perspex.Markup.Xaml/Data/Binding.cs b/src/Markup/Perspex.Markup.Xaml/Data/Binding.cs index 85ec2e0553..27d4672097 100644 --- a/src/Markup/Perspex.Markup.Xaml/Data/Binding.cs +++ b/src/Markup/Perspex.Markup.Xaml/Data/Binding.cs @@ -61,20 +61,11 @@ namespace Perspex.Markup.Xaml.Data /// public object Source { get; set; } - /// - /// Creates a subject that can be used to get and set the value of the binding. - /// - /// The target instance. - /// The target property. May be null. - /// - /// For `ElementName` bindings to elements that are not themselves controls, describes - /// where in the logical tree to begin searching for the named element. - /// - /// An . + /// public ISubject CreateSubject( IPerspexObject target, PerspexProperty targetProperty, - IPerspexObject treeAnchor = null) + object anchor = null) { Contract.Requires(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); } diff --git a/src/Markup/Perspex.Markup.Xaml/Data/MultiBinding.cs b/src/Markup/Perspex.Markup.Xaml/Data/MultiBinding.cs index dbf5ca7925..f8b4767c30 100644 --- a/src/Markup/Perspex.Markup.Xaml/Data/MultiBinding.cs +++ b/src/Markup/Perspex.Markup.Xaml/Data/MultiBinding.cs @@ -49,35 +49,11 @@ namespace Perspex.Markup.Xaml.Data /// public RelativeSource RelativeSource { get; set; } - /// - /// Applies the binding to a property on an instance. - /// - /// The target instance. - /// The target property. - public void Bind(IPerspexObject instance, PerspexProperty property) - { - var subject = CreateSubject(instance, property); - - if (subject != null) - { - Bind(instance, property, subject); - } - } - - /// - /// Creates a subject that can be used to get and set the value of the binding. - /// - /// The target instance. - /// The target property. May be null. - /// - /// For `ElementName` bindings to elements that are not themselves controls, describes - /// where in the logical tree to begin searching for the named element. - /// - /// An . + /// public ISubject CreateSubject( IPerspexObject target, PerspexProperty targetProperty, - IPerspexObject treeAnchor = null) + object anchor = null) { if (Converter == null) { diff --git a/src/Markup/Perspex.Markup.Xaml/Data/StyleResourceBinding.cs b/src/Markup/Perspex.Markup.Xaml/Data/StyleResourceBinding.cs index 390efc6f63..e10eb1a643 100644 --- a/src/Markup/Perspex.Markup.Xaml/Data/StyleResourceBinding.cs +++ b/src/Markup/Perspex.Markup.Xaml/Data/StyleResourceBinding.cs @@ -37,22 +37,22 @@ namespace Perspex.Markup.Xaml.Data public ISubject 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 { 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 observer) { - var host = (_target as IControl) ?? (_treeAnchor as IControl); + var host = (_target as IControl) ?? (_anchor as IControl); if (host != null) { diff --git a/src/Perspex.Base/Data/IBinding.cs b/src/Perspex.Base/Data/IBinding.cs index a182b6adc3..1ad45913f9 100644 --- a/src/Perspex.Base/Data/IBinding.cs +++ b/src/Perspex.Base/Data/IBinding.cs @@ -25,14 +25,16 @@ namespace Perspex.Data /// /// The target instance. /// The target property. May be null. - /// - /// For `ElementName` bindings to elements that are not themselves controls, describes - /// where in the logical tree to begin searching for the named element. - /// + /// An optional anchor from which to locate required context. /// An . + /// + /// 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 + /// parameter can be used to provice this context. + /// ISubject CreateSubject( IPerspexObject target, PerspexProperty targetProperty, - IPerspexObject treeAnchor = null); + object anchor = null); } }