建设公司网站新闻宣传管理制度,营销推广与策划,陕西网站建设培训,人工智能培训机构哪个好在xaml中控件通过绑定静态资源StaticResource来获取样式Style有多种方式#xff0c;TextBlockStyle.xaml是一个ResourceDictionary#xff0c;包含了所需样式 通过相对路径引用 通过后台代码向当前程序的资源中动态添加#xff0c;代码如下#xff1a; 1 ResourceDicti… 在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