internal virtual bool GetValue(string propertyName, ref object value, bool ignoreExpression)
        {
            var objType = this.ObjectType;
            var dp      = DependencyProperty.GetProperty(objType, propertyName);

            if (dp == null)
            {
                var propertyInfo = objType.ResolveProperty(propertyName);
                if (propertyInfo == null)
                {
                    return(false);
                    //throw new XamlException("没有找到" + propertyName + "的定义");
                }
                value = propertyInfo.GetValue(this);
            }
            value = this.GetValue(dp, ignoreExpression);
            return(true);
        }
Ejemplo n.º 2
0
        protected override void Load(object obj, HtmlNode objNode)
        {
            var ctx   = LoadContext.Current;
            var style = ctx.Parent as XamlStyle;

            if (style == null)
            {
                throw new XamlException("Setter的父对象必须为XamlStyle");
            }
            var targetType = style.TargetType;

            if (targetType == null)
            {
                throw new XamlException("请指定正确的Style.TargetType属性");
            }

            var propertyName = objNode.GetAttributeValue("Property", string.Empty);

            if (string.IsNullOrEmpty(propertyName))
            {
                throw new XamlException("请指定正确的Setter.Property属性");
            }

            var setter = obj as Setter;

            setter.Property = DependencyProperty.GetProperty(targetType, propertyName);

            string value = objNode.GetAttributeValue("Value", string.Empty);

            if (!string.IsNullOrEmpty(value))
            {
                //简单值
                var propertyInfo = targetType.ResolveProperty(propertyName);
                PropertiesLoader.SetValue(setter, Setter.ValueProperty, propertyInfo, value);
            }
            else
            {
                var valueNode = objNode.SelectSingleNodeEx("Setter.Value");
                if (valueNode != null)
                {
                    setter.Value = XamlReader.ReadComponent(valueNode.InnerHtml);
                }
            }
        }