/// <summary>
        /// 对元素属性进行绑定操作
        /// </summary>
        /// <param name="attribute">要绑定的元素属性</param>
        /// <param name="context">绑定上下文</param>
        /// <returns>是否成功绑定</returns>
        public bool BindAttribute(IHtmlAttribute attribute, HtmlBindingContext context)
        {
            if (attribute.Name == "datacontext")
            {
                return(false);
            }

            var expression = AttributeExpression.ParseExpression(attribute);

            if (expression == null || !expression.Name.EqualsIgnoreCase("Binding"))
            {
                return(false);
            }

            var dataObject = GetDataObject(expression, context);

            if (dataObject == null)
            {
                attribute.Remove();
                return(true);
            }


            string value = GetBindingValue(expression, dataObject);

            attribute.SetValue(value);

            return(true);
        }
        /// <summary>
        /// 设置属性的值,这会产生一个新的属性,并返回
        /// </summary>
        /// <param name="attribute">要设置值的属性</param>
        /// <param name="value">设置的值</param>
        /// <returns>所创建的新属性</returns>
        public static IHtmlAttribute SetValue(this IHtmlAttribute attribute, string value)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException("attribute");
            }

            var element = attribute.Element;
            var name    = attribute.Name;

            if (element == null)
            {
                throw new InvalidOperationException();
            }

            attribute.Remove();

            return(element.AddAttribute(name, value));
        }
Exemple #3
0
        /// <summary>
        /// 进行属性绑定
        /// </summary>
        /// <param name="attribute">要绑定的属性</param>
        protected virtual void BindAttribute(IHtmlAttribute attribute)
        {
            var expression = BindingExpression.ParseExpression(attribute.Value());

            if (expression == null)
            {
                return;
            }

            var value = GetValue(expression);

            if (value == null)
            {
                attribute.Remove();
            }

            else
            {
                attribute.SetValue(value.ToString());
            }
        }
        /// <summary>
        /// 对元素属性进行绑定操作
        /// </summary>
        /// <param name="attribute">要绑定的元素属性</param>
        /// <param name="context">绑定上下文</param>
        /// <returns>是否成功绑定</returns>
        public bool BindAttribute( IHtmlAttribute attribute, HtmlBindingContext context )
        {
            if ( attribute.Name == "datacontext" )
            return false;

              var expression = AttributeExpression.ParseExpression( attribute );
              if ( expression == null || !expression.Name.EqualsIgnoreCase( "Binding" ) )
            return false;

              var dataObject = GetDataObject( expression, context );

              if ( dataObject == null )
              {
            attribute.Remove();
            return true;
              }

              string value = GetBindingValue( expression, dataObject );

              attribute.SetValue( value );

              return true;
        }