private static ResourceDictionary Load(string filepath)
		{
			var dict = new ResourceDictionary();
			dict.BeginInit();
			dict.Source = new Uri(filepath, UriKind.RelativeOrAbsolute);
			dict.EndInit();
			return dict;
		}
        private static void ApplyResourceDictionary(ResourceDictionary newRd, ResourceDictionary oldRd)
        {
            oldRd.BeginInit();

            foreach (DictionaryEntry r in newRd)
            {
                if (oldRd.Contains(r.Key))
                    oldRd.Remove(r.Key);

                oldRd.Add(r.Key, r.Value);
            }

            oldRd.EndInit();
        }
Exemple #3
0
        private void LoadStyles(ResourceDictionary targetResources)
        {
            targetResources.BeginInit();
            // Basic resources
            targetResources.MergedDictionaries.Add(Freeze(new ResourceDictionary() { Source = new Uri("/Zetbox.Client.WPF;component/AppResources.xaml", UriKind.Relative) }));

            // Init all Converter that need a constructor
            var templateSelectorFactory = container.Resolve<Zetbox.Client.WPF.Toolkit.VisualTypeTemplateSelector.Factory>();
            targetResources["defaultTemplateSelector"] = templateSelectorFactory(null);
            targetResources["listItemTemplateSelector"] = templateSelectorFactory("Zetbox.App.GUI.SingleLineKind");
            targetResources["dashBoardTemplateSelector"] = templateSelectorFactory("Zetbox.App.GUI.DashboardKind");

            // Manually add DefaultStyles and DefaultViews to enable override through Autofac
            targetResources.MergedDictionaries.Add(Freeze(new ResourceDictionary() { Source = new Uri("/Zetbox.Client.WPF;component/Styles/DefaultStyles.xaml", UriKind.Relative) }));
            targetResources.MergedDictionaries.Add(Freeze(new ResourceDictionary() { Source = new Uri("/Zetbox.Client.WPF;component/Styles/DefaultHighlightColorDefinitions.xaml", UriKind.Relative) }));
            // Load registrated dictionaries from autofac
            foreach (var dict in container.Resolve<IEnumerable<Meta<ResourceDictionary>>>().Where(m => WPFHelper.RESOURCE_DICTIONARY_STYLE.Equals(m.Metadata[WPFHelper.RESOURCE_DICTIONARY_KIND])).Select(m => m.Value))
            {
                targetResources.MergedDictionaries.Add(Freeze(dict));
            }

            // For testing only!!!!
            // targetResources.MergedDictionaries.Add(Freeze(new ResourceDictionary() { Source = new Uri("/Zetbox.Client.WPF;component/Styles/BigFontStyles.xaml", UriKind.Relative) }));

            targetResources.MergedDictionaries.Add(Freeze(new ResourceDictionary() { Source = new Uri("/Zetbox.Client.WPF;component/Styles/DefaultViews.xaml", UriKind.Relative) }));
            targetResources.MergedDictionaries.Add(Freeze(new ResourceDictionary() { Source = new Uri("/Zetbox.Client.WPF;component/Styles/CustomControls.xaml", UriKind.Relative) }));
            // Load registrated dictionaries from autofac
            foreach (var dict in container.Resolve<IEnumerable<Meta<ResourceDictionary>>>().Where(m => WPFHelper.RESOURCE_DICTIONARY_VIEW.Equals(m.Metadata[WPFHelper.RESOURCE_DICTIONARY_KIND])).Select(m => m.Value))
            {
                targetResources.MergedDictionaries.Add(Freeze(dict));
            }

            targetResources.EndInit();
        }
Exemple #4
0
        /// <summary>
        /// Set the current theme
        /// </summary>
        /// <param name="name">The name of the theme</param>
        /// <returns>true if the new theme is set, false otherwise</returns>
        public bool SetCurrent(string name)
        {
            if (ThemeDictionary.ContainsKey(name))
            {
                ITheme newTheme = ThemeDictionary[name];
                CurrentTheme = newTheme;

                ResourceDictionary theme = Application.Current.MainWindow.Resources.MergedDictionaries[0];
                ResourceDictionary appTheme = Application.Current.Resources.MergedDictionaries.Count > 0
                                                  ? Application.Current.Resources.MergedDictionaries[0]
                                                  : null;
                theme.BeginInit();
                theme.MergedDictionaries.Clear();
                if (appTheme != null)
                {
                    appTheme.BeginInit();
                    appTheme.MergedDictionaries.Clear();
                }
                else
                {
                    appTheme = new ResourceDictionary();
                    appTheme.BeginInit();
                    Application.Current.Resources.MergedDictionaries.Add(appTheme);
                }
                foreach (Uri uri in newTheme.UriList)
                {
                    ResourceDictionary newDict = new ResourceDictionary {Source = uri};
                    /*AvalonDock and menu style needs to move to the application
                     * 1. AvalonDock needs global styles as floatable windows can be created
                     * 2. Menu's need global style as context menu can be created
                    */
                    if (uri.ToString().Contains("AvalonDock") ||
                        uri.ToString().Contains("Wide;component/Interfaces/Styles/VS2012/Menu.xaml"))
                    {
                        appTheme.MergedDictionaries.Add(newDict);
                    }
                    else
                    {
                        theme.MergedDictionaries.Add(newDict);
                    }
                }
                appTheme.EndInit();
                theme.EndInit();
                _logger.Log("Theme set to " + name, LogCategory.Info, LogPriority.None);
                _eventAggregator.GetEvent<ThemeChangeEvent>().Publish(newTheme);
            }
            return false;
        }