C# 动态加载资源
在xaml中控件通過綁定靜態資源StaticResource來獲取樣式Style有多種方式,TextBlockStyle.xaml是一個ResourceDictionary,包含了所需樣式
通過相對路徑引用
通過后臺代碼向當前程序的資源中動態添加,代碼如下:
1 ResourceDictionary resourceDictionary = new ResourceDictionary(); 2 Application.LoadComponent(resourceDictionary, new Uri("/Test.Resource;component/TextBlockStyle.xaml", UriKind.Relative)); 3 Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);Application.LoadComponent,只支持相對路徑。
通過絕對路徑引用
通過絕對路徑,可以獲取ResourceDictionary下指定Key值的資源。
1 ResourceDictionary normalVersionDict = new ResourceDictionary(); 2 normalVersionDict.Source = new Uri("F:\Github-Myself\KeyBoardEventDemo\WpfApp30\TextBlockStyle.xaml"); 3 var normalVersionDictKeys = normalVersionDict.Keys;?
轉載于:https://www.cnblogs.com/kybs0/p/11507873.html
總結
- 上一篇: 数学之路(3)-机器学习(3)-机器学习
- 下一篇: C#调用C++DLL传递结构体数组的终极