Esempio n. 1
0
        private Theme getTheme()
        {
            var CustomTheme = new CustomThemeJson()
            {
                name = "SomeCustomTheme"
            };
            var themeJson = new ThemesJson()
            {
                CurrentTheme = "SomeTheme", CustomThemes = new[] { CustomTheme }
            };

            return(new Theme(themeJson));
        }
        private void LoadTheme(CustomThemeJson theme)
        {
            Dictionary <string, string> palleteRules = new Dictionary <string, string>();

            foreach (var item in theme.palette)
            {
                palleteRules[item.name] = item.value;
            }

            foreach (var style in theme.styles)
            {
                var styleName = style.name;
                foreach (var prop in style.propertyValuesMap)
                {
                    var propName  = prop.property;
                    var ruleValue = prop.value;

                    // TODO - share with logic in D:\dev\pa2\PowerApps-Client\src\Cloud\DocumentServer.Core\Document\Document\Theme\ControlStyle.cs
                    // Resolve %%, from palette.
                    {
                        var match = Regex.Match(ruleValue, "%Palette.([^%]+)%");
                        if (match.Success)
                        {
                            var group = match.Groups[1];



                            string resourceValue;
                            // Template may refer to a missing rule.
                            if (palleteRules.TryGetValue(group.ToString(), out resourceValue))
                            {
                                ruleValue = ruleValue.Replace(match.Value, resourceValue);
                            }
                        }
                    }

                    ruleValue = ControlTemplateParser.UnescapeReservedName(ruleValue);

                    _styles.GetOrCreate(styleName).Add(propName, ruleValue);
                }
            }
        }