From 957b6f9e5dc6b27ee7773ff23c44974389393b16 Mon Sep 17 00:00:00 2001 From: Tobias Gummesson Date: Mon, 8 Jul 2013 11:40:53 -0700 Subject: [PATCH] If the ParentProperty is a collection the collection itself is the TargetObject (for example when adding Bindings to the MultiBinding.Bindings property). --- .../Project/XamlObjectServiceProvider.cs | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs index 523c477125..9bb120195f 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs @@ -56,14 +56,34 @@ namespace ICSharpCode.WpfDesign.XamlDom /// Gets the target object (the DependencyObject instance on which a property should be set) /// public object TargetObject { - get { return XamlObject.ParentProperty.ParentObject.Instance; } + get { + var parentProperty = XamlObject.ParentProperty; + + if (parentProperty == null) { + return null; + } + + if (parentProperty.IsCollection) { + return parentProperty.ValueOnInstance; + } + + return parentProperty.ParentObject.Instance; + } } /// /// Gets the target dependency property. /// public object TargetProperty { - get { return XamlObject.ParentProperty.DependencyProperty; } + get { + var parentProperty = XamlObject.ParentProperty; + + if (parentProperty == null) { + return null; + } + + return parentProperty.DependencyProperty; + } } #endregion