11using System . Collections . ObjectModel ;
22using System . Windows ;
3+ using MahApps . Metro . Controls ;
34// ReSharper disable ConvertToExtensionBlock
45
56namespace DevTools . Utilities ;
@@ -10,7 +11,6 @@ namespace DevTools.Utilities;
1011/// </summary>
1112public static class ResourceUtils
1213{
13- private const string MahAppsAssemblyName = "MahApps.Metro" ;
1414 private static ResourceDictionary ? _mahAppsControls ;
1515 private static ResourceDictionary ? _mahAppsLightTheme ;
1616 private static ResourceDictionary ? _mahAppsDarkTheme ;
@@ -21,19 +21,30 @@ private static ResourceDictionary GetResource(string assemblyName, string resour
2121 return new ResourceDictionary { Source = uri } ;
2222 }
2323
24+ public static ResourceDictionary GetResource ( Type type , string resourcePath )
25+ {
26+ var assembly = type . Assembly ;
27+ var assemblyName = assembly . GetName ( ) ;
28+
29+ var version = assemblyName . Version ? . ToString ( 3 ) ;
30+ var uri = new Uri ( $ "pack://application:,,,/{ assemblyName . Name } ;v{ version } ;component/{ resourcePath } ", UriKind . Absolute ) ;
31+
32+ return new ResourceDictionary { Source = uri } ;
33+ }
34+
2435 public static ResourceDictionary GetMahAppsControls ( )
2536 {
26- return _mahAppsControls ??= GetResource ( MahAppsAssemblyName , "Styles/Controls.xaml" ) ;
37+ return _mahAppsControls ??= GetResource ( typeof ( HamburgerMenu ) , "Styles/Controls.xaml" ) ;
2738 }
2839
2940 public static ResourceDictionary GetMahAppsLightTheme ( )
3041 {
31- return _mahAppsLightTheme ??= GetResource ( MahAppsAssemblyName , "Styles/Themes/Light.Blue.xaml" ) ;
42+ return _mahAppsLightTheme ??= GetResource ( typeof ( HamburgerMenu ) , "Styles/Themes/Light.Blue.xaml" ) ;
3243 }
3344
3445 public static ResourceDictionary GetMahAppsDarkTheme ( )
3546 {
36- return _mahAppsDarkTheme ??= GetResource ( MahAppsAssemblyName , "Styles/Themes/Dark.Blue.xaml" ) ;
47+ return _mahAppsDarkTheme ??= GetResource ( typeof ( HamburgerMenu ) , "Styles/Themes/Dark.Blue.xaml" ) ;
3748 }
3849
3950 public static void RemoveIfNotNull ( this Collection < ResourceDictionary > mergedDictionaries , ResourceDictionary ? item )
0 commit comments