Exemple #1
0
        /// <inheritdoc />
        public T ToStyle <T>() where T : Style, new()
        {
            //todo improve this ugly code?
            T style = new T();

            FontWeight fontWeight      = PropertyParser.ParseFontWeight(FontWeight);
            FontStyle  fontStyle       = PropertyParser.ParseFontStyle(FontStyle);
            Brush      foreground      = PropertyParser.ConvertArgbToBrush(Foreground);
            Brush      background      = PropertyParser.ParseBackground(Background);
            Thickness  borderThickness = new Thickness(BorderThickness);
            bool       isParsed        = Enum.TryParse(Visibility, out Visibility visibility);

            visibility = isParsed ? visibility : default;

            style.Setters.Add(new Setter {
                Property = Control.FontWeightProperty, Value = fontWeight
            });
            style.Setters.Add(new Setter {
                Property = Control.FontStyleProperty, Value = fontStyle
            });
            style.Setters.Add(new Setter {
                Property = Control.FontSizeProperty, Value = FontSize
            });
            style.Setters.Add(new Setter {
                Property = Control.ForegroundProperty, Value = foreground
            });
            style.Setters.Add(new Setter {
                Property = Control.BackgroundProperty, Value = background
            });
            style.Setters.Add(new Setter {
                Property = Control.BorderThicknessProperty, Value = borderThickness
            });
            style.Setters.Add(new Setter {
                Property = UIElement.VisibilityProperty, Value = visibility
            });

            if (string.IsNullOrWhiteSpace(FontFamily))
            {
                return(style);
            }

            style.Setters.Add(new Setter
            {
                Property = Control.FontFamilyProperty,
                Value    = new FontFamily(PathsHelper.GetUriFromRelativePath(FontFamily), string.Empty)
            });

            return(style);
        }
Exemple #2
0
        /// <inheritdoc />
        public new void BindProperties(T element, ICommandProvider commandProvider = null, IList <StyleModel> styleModels = null)
        {
            if (element is null)
            {
                throw new UIException(nameof(element));
            }

            element.Background = PropertyParser.ParseBackground(Background);

            //Bind panel's children
            foreach (ChildModel childModel in Children)
            {
                element.Children.Add(childModel.ToUIElement(commandProvider, styleModels));
            }

            element.IsItemsHost = IsItemsHost;
        }