SystemTrayMenu/Resources/StaticResources.cs
Peter Kirmeier 26b9a755c3 [Feature] Show hint to find settings and enable by default 'Show function key Settings' #490
(cherry picked from commit 00b4c5ddcc)

Additional changes:
ResourceLoading improved for Window icons
Fix not working OK button of UpdateWindow
2023-08-11 22:29:08 +02:00

85 lines
2.7 KiB
C#

// <copyright file="StaticResources.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace SystemTrayMenu.Resources
{
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using SystemTrayMenu.Utilities;
internal static class StaticResources
{
internal static readonly Icon LoadingIcon = Properties.Resources.Loading;
private static readonly object ApplicationImgSrcLock = new();
private static readonly object LoadingImgSrcLock = new ();
private static ImageSource? applicationgImgSrc;
private static ImageSource? loadingImgSrc;
public static ImageSource? ApplicationImgSrc
{
get
{
if (applicationgImgSrc == null)
{
lock (ApplicationImgSrcLock)
{
if (applicationgImgSrc == null)
{
applicationgImgSrc = LoadFromAssemblyManifestResources("Resources.SystemTrayMenu.png");
applicationgImgSrc?.Freeze(); // Make it accessible for any thread
}
}
}
return applicationgImgSrc;
}
}
public static ImageSource LoadingImgSrc
{
get
{
if (loadingImgSrc == null)
{
lock (LoadingImgSrcLock)
{
if (loadingImgSrc == null)
{
loadingImgSrc = Properties.Resources.Loading.ToBitmapSource();
loadingImgSrc.Freeze(); // Make it accessible for any thread
}
}
}
return loadingImgSrc;
}
}
private static ImageSource? LoadFromAssemblyManifestResources(string name)
{
Assembly myassembly = Assembly.GetExecutingAssembly();
string myname = myassembly.GetName().Name ?? string.Empty;
using (Stream? imgstream = myassembly.GetManifestResourceStream(myname + "." + name))
{
if (imgstream != null)
{
BitmapImage imageSource = new();
imageSource.BeginInit();
imageSource.StreamSource = imgstream;
imageSource.EndInit();
return imageSource;
}
}
return null;
}
}
}