Skip to content

Commit ea2b516

Browse files
committed
fix(MahApp.Metro): HamburgerMenu style conflict due to multiple MahApp.Metro version
1 parent a26cc6d commit ea2b516

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

source/DevTools.Utilities/ResourceUtils.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.ObjectModel;
22
using System.Windows;
3+
using MahApps.Metro.Controls;
34
// ReSharper disable ConvertToExtensionBlock
45

56
namespace DevTools.Utilities;
@@ -10,7 +11,6 @@ namespace DevTools.Utilities;
1011
/// </summary>
1112
public 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)

source/RevitDevTool/View/MainPage.xaml.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ public partial class MainPage
66
{
77
public MainPage(MainViewModel viewModel)
88
{
9-
InitializeComponent();
109
DataContext = viewModel;
10+
11+
Dispatcher.BeginInvoke(new Action(() =>
12+
{
13+
InitializeComponent();
14+
}), System.Windows.Threading.DispatcherPriority.Loaded);
1115
}
1216
}

0 commit comments

Comments
 (0)