Esempio n. 1
0
        private static IPropertyObserver CreateBaseObserver(Type containingType, XamlName propertyName)
        {
            if (propertyName.IsEmpty)
            {
                return(null);
            }

            containingType = propertyName.ResolveContainingType(containingType);

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

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

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

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

            return(null);
        }
Esempio n. 2
0
        public object ConvertFrom(XamlNamespaces namespaces, Uri sourceUri, object value)
        {
            string text = value.ToString().Trim();

            XamlName eventName      = XamlName.FromPrefixedName(text, namespaces);
            Type     containingType = eventName.ResolveContainingType(null);

            if (containingType == null)
            {
                throw new Granular.Exception("Invalid routed event name \"{0}\"", eventName.LocalName);
            }

            RoutedEvent routedEvent = EventManager.GetEvent(containingType, eventName.MemberName);

            if (routedEvent == null)
            {
                throw new Granular.Exception("Can't find a routed event named \"{0}\"", eventName);
            }

            return(routedEvent);
        }
Esempio n. 3
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);
        }