diff options
author | Samantha Houts <samantha@teamredwall.com> | 2016-04-12 11:35:01 -0700 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-04-12 11:35:00 -0700 |
commit | 73defe491f11fc417a22eebcf805ee20df90045a (patch) | |
tree | 82d5587119d509c45837fd651381d24d824e39fd /Xamarin.Forms.Core | |
parent | 76c8c57fb30621272e19d493787836ed8c322b9d (diff) | |
download | xamarin-forms-73defe491f11fc417a22eebcf805ee20df90045a.tar.gz xamarin-forms-73defe491f11fc417a22eebcf805ee20df90045a.tar.bz2 xamarin-forms-73defe491f11fc417a22eebcf805ee20df90045a.zip |
[Core] Can bind properties in BindableObjects added to static resources in XAML (#58)
Resources that are `BindableObject`s will inherit the `Parent`'s `BindingContext` unless they are `Element`s that have non-null `Parent`s.
Diffstat (limited to 'Xamarin.Forms.Core')
-rw-r--r-- | Xamarin.Forms.Core/BindableObject.cs | 2 | ||||
-rw-r--r-- | Xamarin.Forms.Core/Element.cs | 18 |
2 files changed, 19 insertions, 1 deletions
diff --git a/Xamarin.Forms.Core/BindableObject.cs b/Xamarin.Forms.Core/BindableObject.cs index 683d390a..f3482004 100644 --- a/Xamarin.Forms.Core/BindableObject.cs +++ b/Xamarin.Forms.Core/BindableObject.cs @@ -360,7 +360,7 @@ namespace Xamarin.Forms if (fromStyle) context.Attributes |= BindableContextAttributes.IsSetFromStyle; - // else ommitted on purpose + // else omitted on purpose bool currentlyApplying = _applying; diff --git a/Xamarin.Forms.Core/Element.cs b/Xamarin.Forms.Core/Element.cs index a85bb3fb..b6312737 100644 --- a/Xamarin.Forms.Core/Element.cs +++ b/Xamarin.Forms.Core/Element.cs @@ -17,6 +17,8 @@ namespace Xamarin.Forms string _automationId; + IList<BindableObject> _bindableResources; + List<Action<object, ResourcesChangedEventArgs>> _changeHandlers; List<KeyValuePair<string, BindableProperty>> _dynamicResources; @@ -321,6 +323,12 @@ namespace Xamarin.Forms SetChildInheritedBindingContext(child, bc); } + if (_bindableResources != null) + foreach (BindableObject item in _bindableResources) + { + SetInheritedBindingContext(item, BindingContext); + } + base.OnBindingContextChanged(); } @@ -420,6 +428,8 @@ namespace Xamarin.Forms handler(this, new ResourcesChangedEventArgs(values)); if (_dynamicResources == null) return; + if (_bindableResources == null) + _bindableResources = new List<BindableObject>(); foreach (KeyValuePair<string, object> value in values) { List<BindableProperty> changedResources = null; @@ -434,6 +444,14 @@ namespace Xamarin.Forms continue; foreach (BindableProperty changedResource in changedResources) OnResourceChanged(changedResource, value.Value); + + var bindableObject = value.Value as BindableObject; + if (bindableObject != null && (bindableObject as Element)?.Parent == null) + { + if (!_bindableResources.Contains(bindableObject)) + _bindableResources.Add(bindableObject); + SetInheritedBindingContext(bindableObject, BindingContext); + } } } |