ResourceHelper.cs 723 B

123456789101112131415161718192021222324252627
  1. using System.Windows;
  2. namespace Muchinfo.PC.Common.Helpers
  3. {
  4. public class ResourceHelper
  5. {
  6. /// <summary>
  7. /// 获取系统资源
  8. /// </summary>
  9. /// <typeparam name="T"></typeparam>
  10. /// <param name="resourceName">Name of the resource.</param>
  11. /// <returns>``0.</returns>
  12. public static T GetFromeResource<T>(string resourceName) where T : class
  13. {
  14. try
  15. {
  16. var brush = (T)Application.Current.TryFindResource(resourceName);
  17. if (brush == null) return default(T);
  18. return brush;
  19. }
  20. catch
  21. {
  22. return null;
  23. }
  24. }
  25. }
  26. }