开发中代码写法备忘

WPF后台代码调用资源字典

1         public static Style GetResource(string uri, string key)
2         {
3             foreach (ResourceDictionary rd in Application.Current.Resources.MergedDictionaries)
4             {
5                 if (rd.Source == new Uri(uri, UriKind.RelativeOrAbsolute))
6                     return rd[key] as Style;
7             }
8             return null;
9         }

引用代码:

1     rb.Style = ResourceHelper.GetResource("Resources/ButtonStyle.xaml", "btnStyle1");

 

posted @ 2024-11-21 15:21  [春风十里]  阅读(2)  评论(0编辑  收藏  举报