public override void SetValue(XamlObjectElement obj, object value) { MutableObject mutable = value as MutableObject; if (mutable != null) { value = mutable.Object; } Binding binding = value as Binding; if (binding != null && SetBinding(binding, Target)) { return; } if (!typeof(TemplateBindingExpression).IsAssignableFrom(Type)) { TemplateBindingExpression tb = value as TemplateBindingExpression; if (tb != null) { SetTemplateBinding(tb, Target); return; } } // We do this before lists to cover the case where you are setting a list to a list or // a resource dictionary to a resource dictionary, ect // as opposed to adding items to the list or dictionary. // // null is a legal value here because they may have done something like foo="{x:Null}" // if (value == null || Type.IsAssignableFrom(value.GetType())) { accessors.Setter(Target, ConvertValue(Type, value)); return; } if (typeof(IList).IsAssignableFrom(Type)) { AddToCollection(obj, value); return; } if (typeof(IDictionary).IsAssignableFrom(Type)) { AddToDictionary(obj, value); return; } throw Parser.ParseException("Unable to set property {0} to value {1}.", Name, value); }
public override void SetValue(XamlObjectElement obj, object value) { var mutable = value as MutableObject; if (mutable != null) { value = mutable.Object; } if (!typeof(Binding).IsAssignableFrom(Type)) { Binding binding = value as Binding; if (binding != null) { SetBinding(binding, Element.Object); return; } } if (!typeof(TemplateBindingExpression).IsAssignableFrom(Type)) { TemplateBindingExpression tb = value as TemplateBindingExpression; if (tb != null) { SetTemplateBinding(tb, obj.Object); return; } } if (value == null || Type.IsAssignableFrom(value.GetType())) { Accessors.Setter(Element.Object, ConvertValue(Type, value)); return; } if (typeof(IList).IsAssignableFrom(Type)) { AddToCollection(value); return; } throw new XamlParseException( string.Format("XamlAttachedPropertySetter.SetValue: Could not set value '{0}' to the attached property '{1}.{2}'", value, Accessors.DeclaringType, Accessors.Name) ); }