WPF 获取资源文件帮助类

发布时间 2023-09-08 19:37:30作者: 潇潇烟雨
using System;
using System.Reflection;
using System.Windows;

namespace K.Controls.Controls.Helper
{
    public class ResourceHelper
    {
        private static ResourceDictionary _theme;
        internal static T GetResourceInternal<T>(string key)
        {
            if (GetTheme()[key] is T resource)
            {
                return resource;
            }

            return default;
        }
        
        public static ResourceDictionary GetTheme() => _theme == null ? GetStandaloneTheme() : _theme;

        public static ResourceDictionary GetStandaloneTheme()
        {
            return new ResourceDictionary() {Source = new Uri("pack://application:,,,/K.Controls;component/Styles/UserStyle.xaml") };
        }

        public static string GetImageIconByType()
        {
                var imageIcon1 = string.Empty;
                imageIcon1 = Application.Current.Resources[$"{name}" + "LoginIcon"].ToString();
                
                //imageIcon1 = "/K.Controls;component/Images/Black/1.png";
         return imageIcon1; }
}
}