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(); }
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(); }