public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
        {
            if (value.AsString().IsEmpty() || value.AsString() == DefaultValue.AsString())
                return;

            result.Attributes[Attribute.ToString().ToLower()] = value.AsString();
        }
 internal ControlPropertyChangedEventArgs(HtmlObject target, ControlProperty property, Object currentvalue, Object newValue)
 {
     this.Target = target;
     this.Property = property;
     this.OldValue = currentvalue;
     this.NewValue = newValue;
 }
 public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     var boolValue = ConversionHelper.ToBoolean(value);
     if (boolValue == DefaultValue)
         return;
     result.Attributes[Attribute] = boolValue ? ValueIfTrue : ValueIfFalse;
 }
        public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
        {
            if (value.AsString().IsEmpty() || value.AsString() == DefaultValue.AsString())
            {
                return;
            }

            result.Attributes[Attribute.ToString().ToLower()] = value.AsString();
        }
 /// <summary>
 /// Aplica a propriedade à saída de um controle.
 /// </summary>
 /// <param name="target">Controle alvo</param>
 /// <param name="property">Propriedade sendo aplicada</param>
 /// <param name="value">Valor da propriedade sendo aplicada</param>
 /// <param name="result">Resultado da saida da renderização atual.</param>
 public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     if (value != null && value.AsString() != DefaultValue.AsString())
     {
         var strValue = (value ?? "").ToString();
         if (strValue.HasValue())
             result.Styles[CssProperty] = strValue.ToLowerInvariant();
     }
 }
        public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
        {
            var boolValue = ConversionHelper.ToBoolean(value);

            if (boolValue == DefaultValue)
            {
                return;
            }
            result.Attributes[Attribute] = boolValue ? ValueIfTrue : ValueIfFalse;
        }
Example #7
0
 /// <summary>
 /// Aplica a propriedade à saída de um controle.
 /// </summary>
 /// <param name="target">Controle alvo</param>
 /// <param name="property">Propriedade sendo aplicada</param>
 /// <param name="value">Valor da propriedade sendo aplicada</param>
 /// <param name="result">Resultado da saida da renderização atual.</param>
 public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     if (value != null && value.AsString() != DefaultValue.AsString())
     {
         var strValue = (value ?? "").ToString();
         if (strValue.HasValue())
         {
             result.Styles[CssProperty] = strValue.ToLowerInvariant();
         }
     }
 }
Example #8
0
        private ControlPropertySlot GetSlot(ControlProperty property, bool createIfNotExists)
        {
            ControlPropertySlot result = null;

            if (!_slots.TryGetValue(property, out result) && createIfNotExists)
            {
                result           = new ControlPropertySlot(this, property);
                _slots[property] = result;
            }
            return(result);
        }
Example #9
0
        /// <summary>
        /// Atribui um valor para uma propriedade.
        /// </summary>
        /// <param name="property">Propriedade que terá seu valor alterado</param>
        /// <param name="value">Novo valor da propriedade</param>
        public void SetValue(ControlProperty property, Object value)
        {
            var slot = GetSlot(property, true);

            if (slot.StoredValue == value)
            {
                return;
            }
            var oldValue = slot.StoredValue;

            slot.StoredValue = value;
            property.NotifyPropertyChanged(this, oldValue, slot.StoredValue);
        }
Example #10
0
        /// <summary>
        /// Register a property for a Control.
        /// </summary>
        /// <param name="propertyName"></param>
        /// <param name="propertyType"></param>
        /// <param name="ownerType"></param>
        /// <param name="propertyMetadata"></param>
        /// <returns></returns>
        public static ControlProperty Register(String propertyName, Type propertyType, Type ownerType, ControlPropertyMetadata propertyMetadata = null)
        {
            Assert.EmptyString(propertyName, "propertyName");
            Assert.NullArgument(propertyType, "propertyType");
            Assert.NullArgument(ownerType, "ownerType");

            lock (_lockObject)
            {
                if (!typeof(HtmlObject).IsAssignableFrom(ownerType))
                {
                    throw new Exception(String.Format("The type {0} must inherit from HtmlObject in order to own a ControlProperty", ownerType.FullName));
                }

                var result = new ControlProperty()
                {
                    Name         = propertyName,
                    OwnerType    = ownerType,
                    PropertyType = propertyType,
                    Metadata     = propertyMetadata
                };

                if (result.Metadata != null)
                {
                    result.PropertyChangedCallback = result.Metadata.PropertyChangedCallback;
                    result.Applier    = result.Metadata.Applier;
                    result.IsReadOnly = result.Metadata.ReadOnly;
                    if (result.Metadata.DefaultValue != null)
                    {
                        result.DefaultValue = result.Metadata.DefaultValue;
                    }
                    else
                    {
                        result.DefaultValue = ConversionHelper.Default(propertyType);
                    }
                }

                if (propertyType.GetInterfaces().Contains(typeof(INotifyPropertyChanged)))
                {
                    result.TrackingPropertyChangedEvent = true;
                }

                _properties.Add(result);
                _properties = _properties.OrderBy(p => p.Name).ToList();
                _typePropertiesCache.Clear();
                _templatePropertiesCache.Clear();
                _typePropertiesWithAppliersCache.Clear();
                return(result);
            }
        }
Example #11
0
        /// <summary>
        /// Registra uma vinculação de dados a uma propriedade do controle.
        /// </summary>
        /// <param name="targetProperty">Propriedade alvo da vinculação de dados. É a propriedade que receberá o valor resolvido.</param>
        /// <param name="binding">Informações sobre a vinculação de dados.</param>
        public void PropertyBinding(ControlProperty targetProperty, Binding binding)
        {
            var slot = GetSlot(targetProperty, true);

            slot.Binding = binding;
            if (binding == null && _bindings != null)
            {
                _bindings.Remove(slot);
            }
            else
            {
                _bindings = _bindings ?? new List <ControlPropertySlot>();
                _bindings.AddIfNotExists(slot);
            }
        }
Example #12
0
        /// <summary>
        /// Atribui um valor para uma propriedade somente-leitura.
        /// </summary>
        /// <param name="property">Propriedade que terá seu valor alterado.</param>
        /// <param name="value">Novo valor da propriedade</param>
        protected void SetReadOnlyValue(ControlProperty property, Object value)
        {
            if (!property.IsReadOnly)
            {
                throw new InvalidOperationException(String.Format("The property {0}.{1} is not a readonly property.", property.OwnerTypeName, property.PropertyTypeName));
            }
            var slot = GetSlot(property, true);

            if (slot.StoredValue == value)
            {
                return;
            }
            var oldValue = slot.StoredValue;

            slot.SetReadOnlyValue(value);
            property.NotifyPropertyChanged(this, oldValue, slot.StoredValue);
        }
 public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     Object getParams = null;
     var urlStr = value.AsString();
     var uri = new Uri(urlStr, UriKind.RelativeOrAbsolute);
     //url.
     if (GetParamsProperty != null)
         getParams = target.GetValue(GetParamsProperty);
     if (getParams != null)
     {
         IDictionary<String, Object> dict = null;
         if (!(getParams is IDictionary<String, Object>))
             dict = ReflectionHelper.AnonymousToDictionary(getParams);
         else
             dict = (IDictionary<String, Object>)getParams;
         if (uri.Query.HasValue())
             urlStr += urlStr + "&" + Utils.EncodeGetParams(dict);
         else
             urlStr += uri.ToString() + "?" + Utils.EncodeGetParams(dict);
     }
     if (urlStr != null)
         result.Attributes[HtmlAttr.Href] = urlStr;
 }
        public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
        {
            Object getParams = null;
            var    urlStr    = value.AsString();
            var    uri       = new Uri(urlStr, UriKind.RelativeOrAbsolute);

            //url.
            if (GetParamsProperty != null)
            {
                getParams = target.GetValue(GetParamsProperty);
            }
            if (getParams != null)
            {
                IDictionary <String, Object> dict = null;
                if (!(getParams is IDictionary <String, Object>))
                {
                    dict = ReflectionHelper.AnonymousToDictionary(getParams);
                }
                else
                {
                    dict = (IDictionary <String, Object>)getParams;
                }
                if (uri.Query.HasValue())
                {
                    urlStr += urlStr + "&" + Utils.EncodeGetParams(dict);
                }
                else
                {
                    urlStr += uri.ToString() + "?" + Utils.EncodeGetParams(dict);
                }
            }
            if (urlStr != null)
            {
                result.Attributes[HtmlAttr.Href] = urlStr;
            }
        }
Example #15
0
        /// <summary>
        /// Altera o aplicador de uma propriedade para a instancia do controle.
        /// Apenas a instancia atual é afetada.
        /// </summary>
        /// <param name="property">Propriedade que terá seu aplicador alterado.</param>
        /// <param name="applier">Aplicador customizado.</param>
        void IControlInstanceAdapter.SetCustomApplier(ControlProperty property, IControlPropertyApplier applier)
        {
            var slot = GetSlot(property, true);

            slot.CustomApplier = applier;
        }
Example #16
0
 /// <summary>
 /// Registra uma vinculação de propriedades 'template'.
 /// </summary>
 /// <param name="targetProperty">Propriedade alvo. É a propriedade que irá receber o valor resolvido do binding.</param>
 /// <param name="sourceProperty">Propriedade fonte. É a propriedade no controle que detém a propriedade 'template'. O valor dessa propriedadade
 /// é repassada para <paramref name="targetProperty"/> e ela não é renderizada no controle fonte.</param>
 public void TemplateBinding(ControlProperty targetProperty, ControlProperty sourceProperty)
 {
     _templateBindings = _templateBindings ?? new List <ControlPropertyTemplateBinding>();
     _templateBindings.Add(new ControlPropertyTemplateBinding(targetProperty, sourceProperty));
 }
Example #17
0
        /// <summary>
        /// Register a property for a Control.
        /// </summary>
        /// <param name="propertyName"></param>
        /// <param name="propertyType"></param>
        /// <param name="ownerType"></param>
        /// <param name="propertyMetadata"></param>
        /// <returns></returns>
        public static ControlProperty Register(String propertyName, Type propertyType, Type ownerType, ControlPropertyMetadata propertyMetadata = null)
        {
            Assert.EmptyString(propertyName, "propertyName");
            Assert.NullArgument(propertyType, "propertyType");
            Assert.NullArgument(ownerType, "ownerType");

            lock (_lockObject)
            {
                if (!typeof(HtmlObject).IsAssignableFrom(ownerType))
                    throw new Exception(String.Format("The type {0} must inherit from HtmlObject in order to own a ControlProperty", ownerType.FullName));

                var result = new ControlProperty()
                {
                    Name = propertyName,
                    OwnerType = ownerType,
                    PropertyType = propertyType,
                    Metadata = propertyMetadata
                };

                if (result.Metadata != null)
                {
                    result.PropertyChangedCallback = result.Metadata.PropertyChangedCallback;
                    result.Applier = result.Metadata.Applier;
                    result.IsReadOnly = result.Metadata.ReadOnly;
                    if (result.Metadata.DefaultValue != null)
                        result.DefaultValue = result.Metadata.DefaultValue;
                    else
                        result.DefaultValue = ConversionHelper.Default(propertyType);
                }

                if (propertyType.GetInterfaces().Contains(typeof(INotifyPropertyChanged)))
                    result.TrackingPropertyChangedEvent = true;

                _properties.Add(result);
                _properties = _properties.OrderBy(p => p.Name).ToList();
                _typePropertiesCache.Clear();
                _templatePropertiesCache.Clear();
                _typePropertiesWithAppliersCache.Clear();
                return result;
            }
        }
Example #18
0
 /// <summary>
 /// Retorna o valor de uma propriedade.
 /// </summary>
 /// <typeparam name="T">Tipo esperado da propriedade. Se o tipo especificado for diferente do tipo armazenado, uma exceção será levantada.</typeparam>
 /// <param name="property">Propriedade requisitada.</param>
 /// <returns>Retorna o valor corrente da propriedade ou seu valor default definido no momento do registro.</returns>
 /// <exception cref="System.InvalidCastException">Caso o tipo especificado em "T" não seja compatível com o tipo do dado armazenado.</exception>
 public T GetValue <T>(ControlProperty property)
 {
     return((T)GetValue(property));
 }
Example #19
0
        /// <summary>
        /// Retorna o valor de uma propriedade.
        /// </summary>
        /// <param name="property">Propriedade requisitada.</param>
        /// <returns>Retorna o valor corrente da propriedade ou seu valor default definido no momento do registro.</returns>
        public Object GetValue(ControlProperty property)
        {
            var slot = GetSlot(property, false);

            return(slot == null ? property.DefaultValue : slot.CurrentValue);
        }
Example #20
0
        internal void Resolve(HtmlObject instance, ControlProperty targetProperty)
        {
            Object value = null;

            if (ValueProvider != null)
            {
                value = ValueProvider.GetValue(instance.DataItem);
            }
            else if (_pathParts != null || _resolvePending)
            {
                if (_resolvePending)
                {
                    CompilePropertyPath();
                }
                var data = instance.DataItem;
                for (var i = 0; i < _pathParts.Length; i++)
                {
                    var key = _pathParts[i];
                    try
                    {
                        switch (_resolveMethods[i])
                        {
                        case ResolveMethod.PropertyValue:
                            data = ReflectionHelper.ReadProperty(data, key); break;

                        case ResolveMethod.ViewDataEntry:
                            data = instance.CurrentContext[key]; break;

                        case ResolveMethod.MethodCall:
                            data = ReflectionHelper.InvokeInstanceMethod(data, key); break;

                        case ResolveMethod.CurrentDataItem:
                            data = instance.DataItem; break;

                        case ResolveMethod.VisualTreeObject:
                            throw new NotImplementedException();
                        }
                        if (data == null)
                        {
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new BindingException(String.Format("Error on resolve property path {0} to property {1}.{2}", PropertyPath, instance.GetType().Name, targetProperty.Name), ex);
                    }
                }
                value = data;
            }
            else
            {
                value = instance.DataItem;
            }

            if (Formatter != null)
            {
                value = Formatter.Format(value);
                if (Formatter.Align != TextAlignment.Default)
                {
                    instance.SetValue(HtmlControl.TextAlignProperty, Formatter.Align);
                }
            }
            if (!String.IsNullOrEmpty(FormatString))
            {
                value = String.Format(FormatString, value);
            }

            instance.SetValue(targetProperty, value);
        }
Example #21
0
        private void ApplyProperties()
        {
            _renderResult.Begin();
            var propertyList = ControlProperty.GetPropertiesWithAppliersForType(this.GetType());

            foreach (var property in propertyList)
            {
                var slot = GetSlot(property, false);
                if (slot == null &&
                    property.Applier != null)
                {
                    property.Applier.ApplyProperty(this, property, property.DefaultValue, _renderResult);
                }

                else if (slot != null &&
                         slot.CurrentApplier != null &&
                         slot.LastTemplateBindingSessionId != CurrentContext.RenderSessionId)
                {
                    slot.CurrentApplier.ApplyProperty(this, property, slot.CurrentValue, _renderResult);
                }
            }

            if (_styles != null)
            {
                foreach (var item in _styles)
                {
                    _renderResult.Styles[item.Style] = item.Value;
                }
            }

            if (_attributes != null)
            {
                foreach (var item in _attributes)
                {
                    _renderResult.Attributes[item.Name] = item.Value;
                }
            }

            if (_cssClasses != null)
            {
                var cssClass = _renderResult.Attributes[HtmlAttr.Class];
                if (cssClass.HasValue())
                {
                    var current = cssClass.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                    foreach (var cssItem in _cssClasses)
                    {
                        current.AddIfNotExists(cssItem);
                    }

                    cssClass = "";
                    foreach (var cssItem in current)
                    {
                        cssClass += cssItem + " ";
                    }
                    _renderResult.Attributes[HtmlAttr.Class] = cssClass.Trim();
                }
                else
                {
                    foreach (var cssItem in _cssClasses)
                    {
                        cssClass += cssItem + " ";
                    }
                    _renderResult.Attributes[HtmlAttr.Class] = cssClass.Trim();
                }
            }

            if (_renderResult.Styles.Count > 0)
            {
                _renderResult.Attributes[HtmlAttr.Style] = _renderResult.Styles.ToStyleString();
            }
        }
 /// <summary>
 /// Aplica a propriedade à saída de um controle.
 /// </summary>
 /// <param name="target">Controle alvo</param>
 /// <param name="property">Propriedade sendo aplicada</param>
 /// <param name="value">Valor da propriedade sendo aplicada</param>
 /// <param name="result">Resultado da saida da renderização atual.</param>
 public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     if (value != null && value.AsString() != DefaultValue.AsString())
         result.Styles[CssProperty] = CssConfig.GetItemNameFromEnum(property.PropertyType, value);
 }
Example #23
0
 public static T SetProperty <T>(this T control, ControlProperty property, Object value) where T : HtmlObject
 {
     control.SetValue(property, value);
     return(control);
 }
Example #24
0
 public static T SetTemplateBinding <T>(this T control, ControlProperty targetProperty, ControlProperty sourceProperty) where T : HtmlObject
 {
     control.TemplateBinding(targetProperty, sourceProperty);
     return(control);
 }
Example #25
0
 protected override void ApplyValueProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     result.InnerText.Append(value.AsString());
 }
 public HyperLinkHrefPropertyApplier(ControlProperty getParamsProperty = null)
 {
     this.GetParamsProperty = getParamsProperty;
 }
 public HyperLinkHrefPropertyApplier(ControlProperty getParamsProperty = null)
 {
     this.GetParamsProperty = getParamsProperty;
 }
Example #28
0
 public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
 }
Example #29
0
        internal void Resolve(HtmlObject instance, ControlProperty targetProperty)
        {
            Object value = null;
            if (ValueProvider != null)
                value = ValueProvider.GetValue(instance.DataItem);
            else if (_pathParts != null || _resolvePending)
            {
                if (_resolvePending)
                    CompilePropertyPath();
                var data = instance.DataItem;
                for (var i = 0; i < _pathParts.Length; i++)
                {
                    var key = _pathParts[i];
                    try
                    {
                        switch (_resolveMethods[i])
                        {
                            case ResolveMethod.PropertyValue:
                                data = ReflectionHelper.ReadProperty(data, key); break;
                            case ResolveMethod.ViewDataEntry:
                                data = instance.CurrentContext[key]; break;
                            case ResolveMethod.MethodCall:
                                data = ReflectionHelper.InvokeInstanceMethod(data, key); break;
                            case ResolveMethod.CurrentDataItem:
                                data = instance.DataItem; break;
                            case ResolveMethod.VisualTreeObject:
                                throw new NotImplementedException();
                        }
                        if (data == null)
                            break;
                    }
                    catch (Exception ex)
                    {
                        throw new BindingException(String.Format("Error on resolve property path {0} to property {1}.{2}", PropertyPath, instance.GetType().Name, targetProperty.Name), ex);
                    }
                }
                value = data;
            }
            else
                value = instance.DataItem;

            if (Formatter != null)
            {
                value = Formatter.Format(value);
                if (Formatter.Align != TextAlignment.Default)
                    instance.SetValue(HtmlControl.TextAlignProperty, Formatter.Align);
            }
            if (!String.IsNullOrEmpty(FormatString))
                value = String.Format(FormatString, value);

            instance.SetValue(targetProperty, value);
        }
 /// <summary>
 /// Aplica a propriedade à saída de um controle.
 /// </summary>
 /// <param name="target">Controle alvo</param>
 /// <param name="property">Propriedade sendo aplicada</param>
 /// <param name="value">Valor da propriedade sendo aplicada</param>
 /// <param name="result">Resultado da saida da renderização atual.</param>
 public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     Callback.Invoke(target, property, value, result);
 }
Example #31
0
 protected override void ApplyValueProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     if (value.AsString().HasValue())
         result.Attributes[HtmlAttr.Value] = value.AsString();
 }
 internal ControlPropertySlot(HtmlObject owner, ControlProperty property)
 {
     _owner        = new WeakReference(owner);
     this.Property = property;
 }
Example #33
0
 protected override void ApplyValueProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     result.InnerText.Append(value.AsString());
 }
 /// <summary>
 /// Aplica a propriedade à saída de um controle.
 /// </summary>
 /// <param name="target">Controle alvo</param>
 /// <param name="property">Propriedade sendo aplicada</param>
 /// <param name="value">Valor da propriedade sendo aplicada</param>
 /// <param name="result">Resultado da saida da renderização atual.</param>
 public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     Callback.Invoke(target, property, value, result);
 }
Example #35
0
 public static T SetBinding <T>(this T control, ControlProperty property, String propertyPath, String formatString) where T : HtmlObject
 {
     control.PropertyBinding(property, new Binding(propertyPath, null, formatString));
     return(control);
 }
 internal ControlPropertySlot(HtmlObject owner, ControlProperty property)
 {
     _owner = new WeakReference(owner);
     this.Property = property;
 }
Example #37
0
 public static T SetBinding <T>(this T control, ControlProperty property, IValueProvider valueProvider, String formatString) where T : HtmlObject
 {
     control.PropertyBinding(property, new Binding(valueProvider, null, formatString));
     return(control);
 }