Beispiel #1
0
        public IPropertyObserver CreatePropertyObserver(Type baseValueType)
        {
            Type containingType = PropertyName.ResolveContainingType(baseValueType);

            DependencyProperty dependencyProperty = DependencyProperty.GetProperty(containingType, PropertyName.MemberName);

            if (dependencyProperty != null)
            {
                return(new DependencyPropertyObserver(dependencyProperty));
            }

            PropertyInfo propertyInfo = containingType.GetInstanceProperty(PropertyName.MemberName);

            if (propertyInfo != null)
            {
                return(new ClrPropertyObserver(propertyInfo, new object[0]));
            }

            return(null);
        }
Beispiel #2
0
        public IPropertyObserver CreatePropertyObserver(Type baseValueType)
        {
            DependencyProperty dependencyProperty = DependencyProperty.GetProperty(baseValueType, PropertyName);

            if (dependencyProperty != null)
            {
                return(new DependencyPropertyObserver(dependencyProperty));
            }

            Type propertyContainingType = PropertyName.IsMemberName ? TypeParser.ParseType(PropertyName.ContainingTypeName) : baseValueType;

            PropertyInfo propertyInfo = propertyContainingType.GetInstanceProperty(PropertyName.MemberName);

            if (propertyInfo != null)
            {
                return(new ClrPropertyObserver(propertyInfo, new object[0]));
            }

            return(null);
        }
Beispiel #3
0
        public object ConvertFrom(XamlNamespaces namespaces, Uri sourceUri, object value)
        {
            string text = value.ToString().Trim();

            int typeSeparatorIndex = text.IndexOf(".");

            if (typeSeparatorIndex == -1)
            {
                throw new Granular.Exception("Dependency property \"{0}\" does not contain owner type name", text);
            }

            Type ownerType = TypeParser.ParseType(text.Substring(0, typeSeparatorIndex), namespaces);
            DependencyProperty dependencyProperty = DependencyProperty.GetProperty(ownerType, text.Substring(typeSeparatorIndex + 1));

            if (dependencyProperty == null)
            {
                throw new Granular.Exception("Can't find dependency property named \"{0}\"", text);
            }

            return(dependencyProperty);
        }
Beispiel #4
0
        public static bool TryGetValue(object target, XamlName propertyName, out object value)
        {
            Type containingType = propertyName.ResolveContainingType(target.GetType());

            DependencyProperty dependencyProperty = DependencyProperty.GetProperty(containingType, propertyName.MemberName);

            if (dependencyProperty != null && target is DependencyObject)
            {
                value = ((DependencyObject)target).GetValue(dependencyProperty);
                return(true);
            }

            PropertyInfo propertyInfo = containingType.GetInstanceProperty(propertyName.MemberName);

            if (propertyInfo != null && !propertyInfo.GetIndexParameters().Any())
            {
                value = propertyInfo.GetValue(target, new object[0]);
                return(true);
            }

            value = null;
            return(false);
        }
Beispiel #5
0
        public static bool TryGetValue(object target, XamlName propertyName, out object value)
        {
            DependencyProperty dependencyProperty = DependencyProperty.GetProperty(target.GetType(), propertyName);

            if (dependencyProperty != null && target is DependencyObject)
            {
                value = ((DependencyObject)target).GetValue(dependencyProperty);
                return(true);
            }

            Type propertyContainingType = propertyName.IsMemberName ? TypeParser.ParseType(propertyName.ContainingTypeName) : target.GetType();

            PropertyInfo propertyInfo = propertyContainingType.GetInstanceProperty(propertyName.MemberName);

            if (propertyInfo != null && !propertyInfo.GetIndexParameters().Any())
            {
                value = propertyInfo.GetValue(target, new object[0]);
                return(true);
            }

            value = null;
            return(false);
        }
Beispiel #6
0
 public bool TryGetDependencyProperty(Type containingType, out DependencyProperty dependencyProperty)
 {
     dependencyProperty = DependencyProperty.GetProperty(PropertyName.ResolveContainingType(containingType), PropertyName.MemberName);
     return(dependencyProperty != null);
 }
Beispiel #7
0
 public bool TryGetDependencyProperty(Type containingType, out DependencyProperty dependencyProperty)
 {
     dependencyProperty = DependencyProperty.GetProperty(containingType, PropertyName);
     return(dependencyProperty != null);
 }