本文整理汇总了C#中System.Windows.ResourceDictionary.BeginInit方法的典型用法代码示例。如果您正苦于以下问题:C# ResourceDictionary.BeginInit方法的具体用法?C# ResourceDictionary.BeginInit怎么用?C# ResourceDictionary.BeginInit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.ResourceDictionary
的用法示例。
在下文中一共展示了ResourceDictionary.BeginInit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
private static ResourceDictionary Load(string filepath)
{
var dict = new ResourceDictionary();
dict.BeginInit();
dict.Source = new Uri(filepath, UriKind.RelativeOrAbsolute);
dict.EndInit();
return dict;
}
示例2: ApplyResourceDictionary
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();
}
示例3: LoadStyles
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();
}
示例4: SetCurrent
/// <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;
}