예제 #1
0
파일: Themes.cs 프로젝트: configare/hispeed
        /// <summary>
        /// Deserializes a theme from a given %XmlTheme:Telerik.WinControls.XmlTheme%
        /// instance. Resulting theme is registered within ThemeReolutionService and can be obtained using the following
        /// ThemeResolutionService.GetTheme(xmlTheme.ThemeName)
        /// </summary>
        /// <param name="xmlTheme">An instance of the <see cref="XmlTheme"/>class
        /// which is deserialized.</param>
        /// <param name="registerBuildersWithThemeResService">Defines whether new <see cref="StyleBuilderRegistration"/>
        /// instances are added in the <see cref="ThemeResolutionService"/>.</param>
        public static void Deserialize(XmlTheme xmlTheme, bool registerBuildersWithThemeResService)
        {
            //ThemeResolutionService.BeginEditTheme(xmlTheme.ThemeName);

            if (string.IsNullOrEmpty(xmlTheme.ThemeName))
            {
                return;
            }

            ThemeResolutionService.SuspendThemeChange();

            try
            {
                //Copy theme parameters
                ThemeResolutionService.EnsureThemeRegistered(xmlTheme.ThemeName);
                Theme themeInstance = ThemeResolutionService.GetTheme(xmlTheme.ThemeName);
                foreach (KeyValuePair <string, object> dictionaryEntry in xmlTheme.ThemeProperties)
                {
                    themeInstance.ThemeProperties[dictionaryEntry.Key] = dictionaryEntry.Value;
                }

                string[] themeNames = xmlTheme.ThemeName.Split(',', ';');

                if (xmlTheme.HasRepository)
                {
                    foreach (string themeName in themeNames)
                    {
                        //If a repository for this theme already exists, both are merged.
                        ThemeResolutionService.RegisterThemeRepository(xmlTheme.StyleRepository, themeName.Trim());
                    }
                }

                //Register StyleBuilders
                if (registerBuildersWithThemeResService && xmlTheme.BuilderRegistrations != null)
                {
                    foreach (XmlStyleBuilderRegistration registration in xmlTheme.BuilderRegistrations)
                    {
                        foreach (string themeName in themeNames)
                        {
                            ThemeResolutionService.RegisterStyleBuilder(registration.GetRegistration(), themeName.Trim());
                        }
                    }
                }
            }
            finally
            {
                ThemeResolutionService.ResumeThemeChange();
            }
        }