Ejemplo n.º 1
0
        private CreateStyleDictionaryFromDeclarationBlockResult <TDependencyProperty> CreateStyleDictionaryFromDeclarationBlock(
            List <CssNamespace> namespaces,
            StyleDeclarationBlock declarationBlock,
            Type matchedType,
            TDependencyObject dependencyObject)
        {
            var result = new CreateStyleDictionaryFromDeclarationBlockResult <TDependencyProperty>();

            foreach (var styleDeclaration in declarationBlock)
            {
                var property = cssTypeHelper.GetDependencyProperty(namespaces, matchedType, styleDeclaration.Property);

                if (property == null)
                {
                    continue;
                }

                try
                {
                    var propertyValue = cssTypeHelper.GetPropertyValue(matchedType, dependencyObject, styleDeclaration.Value, property, namespaces);

                    result.PropertyStyleValues[property] = propertyValue;
                }
                catch
                {
                    result.Errors.Add($"Cannot get property-value for '{styleDeclaration.Property}' with value '{styleDeclaration.Value}'!");
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        private Dictionary <TDependencyProperty, object> CreateStyleDictionaryFromDeclarationBlock(
            List <CssNamespace> namespaces,
            StyleDeclarationBlock declarationBlock,
            Type matchedType,
            TDependencyObject dependencyObject)
        {
            var propertyStyleValues = new Dictionary <TDependencyProperty, object>();

            foreach (var styleDeclaration in declarationBlock)
            {
                var property = cssTypeHelper.GetDependencyProperty(namespaces, matchedType, styleDeclaration.Property);

                if (property == null)
                {
                    continue;
                }

                var propertyValue = cssTypeHelper.GetPropertyValue(matchedType, dependencyObject, styleDeclaration.Value, property);

                propertyStyleValues[property] = propertyValue;
            }

            return(propertyStyleValues);
        }
Ejemplo n.º 3
0
        private Dictionary <TDependencyProperty, object> CreateStyleDictionaryFromDeclarationBlock(
            List <CssNamespace> namespaces,
            StyleDeclarationBlock declarationBlock,
            Type matchedType,
            TDependencyObject dependencyObject)
        {
            var propertyStyleValues = new Dictionary <TDependencyProperty, object>();

            foreach (var i in declarationBlock)
            {
                TDependencyProperty property;

                if (i.Property.Contains("."))
                {
                    string typename     = null;
                    string propertyName = null;

                    if (i.Property.Contains("|"))
                    {
                        var strs  = i.Property.Split('|', '.');
                        var alias = strs[0];
                        var namespaceFragments = namespaces
                                                 .First(x => x.Alias == alias)
                                                 .Namespace
                                                 .Split(',');

                        typename     = $"{namespaceFragments[0]}.{strs[1]}, {string.Join(",", namespaceFragments.Skip(1))}";
                        propertyName = strs[2];
                    }
                    else
                    {
                        var strs = i.Property.Split('.');
                        var namespaceFragments = namespaces
                                                 .First(x => x.Alias == "")
                                                 .Namespace
                                                 .Split(',');

                        typename     = $"{namespaceFragments[0]}.{strs[0]}, {string.Join(",", namespaceFragments.Skip(1))}";
                        propertyName = strs[1];
                    }

                    property = dependencyPropertyService.GetBindableProperty(Type.GetType(typename), propertyName);
                }
                else
                {
                    property = dependencyPropertyService.GetBindableProperty(matchedType, i.Property);
                }

                if (property == null)
                {
                    continue;
                }

                object propertyValue = null;
                if (i.Value is string &&
                    ((string)i.Value).StartsWith("{", StringComparison.Ordinal))
                {
                    propertyValue = markupExpressionParser.ProvideValue((string)i.Value, dependencyObject);
                }
                else
                {
                    propertyValue = dependencyPropertyService.GetBindablePropertyValue(matchedType, property, i.Value);
                }

                propertyStyleValues[property] = propertyValue;
            }

            return(propertyStyleValues);
        }