mirror of
https://github.com/yaobiao131/downkyicore.git
synced 2025-08-10 00:52:31 +00:00
51 lines
1.4 KiB
C#
51 lines
1.4 KiB
C#
using Avalonia;
|
|
using Avalonia.Media;
|
|
using Avalonia.Threading;
|
|
|
|
namespace DownKyi.Utils;
|
|
|
|
public static class DictionaryResource
|
|
{
|
|
/// <summary>
|
|
/// 从资源获取颜色的16进制字符串
|
|
/// </summary>
|
|
/// <param name="resourceKey"></param>
|
|
/// <returns></returns>
|
|
public static string GetColor(string resourceKey)
|
|
{
|
|
var obj = Dispatcher.UIThread.Invoke(() =>
|
|
{
|
|
object? obj = null;
|
|
Application.Current?.TryGetResource(resourceKey, Application.Current.ActualThemeVariant, out obj);
|
|
return obj;
|
|
});
|
|
return obj == null ? "#00000000" : ((Color)obj).ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 从资源获取字符串
|
|
/// </summary>
|
|
/// <param name="resourceKey"></param>
|
|
/// <returns></returns>
|
|
public static string GetString(string resourceKey)
|
|
{
|
|
var obj = Dispatcher.UIThread.Invoke(() =>
|
|
{
|
|
object? obj = null;
|
|
Application.Current?.TryGetResource(resourceKey, Application.Current.ActualThemeVariant, out obj);
|
|
return obj;
|
|
});
|
|
return obj == null ? "" : (string)obj;
|
|
}
|
|
|
|
public static T Get<T>(string resourceKey)
|
|
{
|
|
var obj = Dispatcher.UIThread.Invoke(() =>
|
|
{
|
|
object? obj = null;
|
|
Application.Current?.TryGetResource(resourceKey, Application.Current.ActualThemeVariant, out obj);
|
|
return obj;
|
|
});
|
|
return (T)obj;
|
|
}
|
|
} |