private XamlPropertySetter XamlImplicitAttachedPropertyForName(object target, string name) { Accessors accessors; var dictKey = new CachedAccessorKey(name, Type); if (!XamlContext.AttachedPropertyAccessorCache.TryGetValue(dictKey, out accessors)) { accessors = CreateAttachedAccessors(this, Type, name); XamlContext.AttachedPropertyAccessorCache.Add(dictKey, accessors); } return(XamlAttachedPropertySetter.Create(this, accessors)); }
private XamlReflectionPropertySetter XamlReflectionPropertyForName(Type target, string name) { // If there's a normal CLR property of this name, great! We do everything as normal. If there's // no CLR property, we need to check for the existence of a DependencyProperty of that name. If // the DP exists, we should create a XamlReflectionPropertySetter with a getter/setter that throws // an exception. This allows us to do something like: <Rectangle SomeDp={Binding} /> when SomeDp // does not have a CLR wrapper property. Accessors accessors; var key = new CachedAccessorKey(name, target); if (!XamlContext.PropertyAccessorCache.TryGetValue(key, out accessors)) { PropertyInfo p = target.GetProperty(PropertyName(name), XamlParser.PROPERTY_BINDING_FLAGS); DependencyProperty dp; if (p != null) { accessors = new Accessors( CreateGetter(p.GetGetMethod(true)), CreateSetter(p.GetSetMethod(true)), p.PropertyType, p.Name, Helper.GetConverterCreatorFor(p, p.PropertyType), p.DeclaringType ); } else if (Deployment.Current.MajorVersion >= 4) { // The SL4 parser does not allow you to bind to a DP with no CLR wrapper accessors = null; } else if (DependencyProperty.TryLookup(Deployment.Current.Types.TypeToKind(target), name, out dp) && !dp.IsAttached) { accessors = new Accessors( (o) => { throw new XamlParseException(string.Format("The property {0} was not found on element {1}.", name, target.Name)); }, (o, a) => { throw new XamlParseException(string.Format("The property {0} was not found on element {1}.", name, target.Name)); }, dp.PropertyType, dp.Name, Helper.GetConverterCreatorFor(dp.PropertyType), dp.DeclaringType ); } XamlContext.PropertyAccessorCache.Add(key, accessors); } return(XamlReflectionPropertySetter.Create(this, Object, accessors)); }
private XamlPropertySetter LookupAttachedProperty(IXamlNode reader) { Accessors accessors; var key = new CachedAccessorKey(reader.LocalName, Parser.ResolveType()); if (!XamlContext.AttachedPropertyAccessorCache.TryGetValue(key, out accessors)) { if (key.Type != null && key.Name != null) { var name = AttachedPropertyName(key.Name); accessors = CreateAttachedAccessors(this, key.Type, name); } XamlContext.AttachedPropertyAccessorCache.Add(key, accessors); } return(XamlAttachedPropertySetter.Create(this, accessors)); }
private XamlPropertySetter LookupAttachedProperty (XmlReader reader) { Accessors accessors; var key = new CachedAccessorKey (reader.LocalName, Parser.ResolveType ()); if (!XamlContext.AttachedPropertyAccessorCache.TryGetValue (key, out accessors)) { if (key.Type != null && key.Name != null) { var name = AttachedPropertyName (key.Name); accessors = CreateAttachedAccessors (this, key.Type, name); } XamlContext.AttachedPropertyAccessorCache.Add (key, accessors); } return XamlAttachedPropertySetter.Create (this, accessors); }
private XamlPropertySetter XamlImplicitAttachedPropertyForName (object target, string name) { Accessors accessors; var dictKey = new CachedAccessorKey (name, Type); if (!XamlContext.AttachedPropertyAccessorCache.TryGetValue (dictKey, out accessors)) { accessors = CreateAttachedAccessors (this, Type, name); XamlContext.AttachedPropertyAccessorCache.Add (dictKey, accessors); } return XamlAttachedPropertySetter.Create (this, accessors); }
private XamlReflectionPropertySetter XamlReflectionPropertyForName (Type target, string name) { // If there's a normal CLR property of this name, great! We do everything as normal. If there's // no CLR property, we need to check for the existence of a DependencyProperty of that name. If // the DP exists, we should create a XamlReflectionPropertySetter with a getter/setter that throws // an exception. This allows us to do something like: <Rectangle SomeDp={Binding} /> when SomeDp // does not have a CLR wrapper property. Accessors accessors; var key = new CachedAccessorKey (name, target); if (!XamlContext.PropertyAccessorCache.TryGetValue (key, out accessors)) { PropertyInfo p = target.GetProperty (PropertyName (name), XamlParser.PROPERTY_BINDING_FLAGS); DependencyProperty dp; if (p != null) { accessors = new Accessors ( CreateGetter (p.GetGetMethod (true)), CreateSetter (p.GetSetMethod (true)), p.PropertyType, p.Name, Helper.GetConverterCreatorFor (p, p.PropertyType), p.DeclaringType ); } else if (Deployment.Current.MajorVersion >= 4) { // The SL4 parser does not allow you to bind to a DP with no CLR wrapper accessors = null; } else if (DependencyProperty.TryLookup (Deployment.Current.Types.TypeToKind (target), name, out dp) && !dp.IsAttached) { accessors = new Accessors ( (o) => { throw new XamlParseException (string.Format ("The property {0} was not found on element {1}.", name, target.Name)); }, (o, a) => { throw new XamlParseException (string.Format ("The property {0} was not found on element {1}.", name, target.Name)); }, dp.PropertyType, dp.Name, Helper.GetConverterCreatorFor (dp.PropertyType), dp.DeclaringType ); } XamlContext.PropertyAccessorCache.Add (key, accessors); } return XamlReflectionPropertySetter.Create (this, Object, accessors); }