spiegelp / MaterialDesignExtensions

Material Design Extensions is based on Material Design in XAML Toolkit to provide additional controls and features for WPF apps
https://spiegelp.github.io/MaterialDesignExtensions/
MIT License
754 stars 122 forks source link

Fail loading MaterialDesignThemes.WPF 4.0.0 #134

Open ananthk opened 3 years ago

ananthk commented 3 years ago

Issue:

When using MaterialDesignThemes.WPF.4.0.0 Creating an instance of "MaterialDesignExtensions.Themes.PaletteHelper" fails with NullReferenceException.

at MaterialDesignExtensions.Themes.ResourceDictionaryExtensions.GetExtendedTheme(ResourceDictionary resourceDictionary) at MaterialDesignExtensions.Themes.PaletteHelper.GetExtendedTheme() at UxControls.Themes.ThemeHelper.ModifyTheme(Action1 modificationAction) in C:\DDrive\Temp\ShellApp\UxControls\Themes\ThemeHelper.cs:line 41 at UxControls.Themes.ThemeHelper.SetTheme(ColorTheme colors) in C:\DDrive\Temp\ShellApp\UxControls\Themes\ThemeHelper.cs:line 12 at T1ShellApp.MainWindow..ctor() in C:\DDrive\Temp\ShellApp\T1ShellApp\MainWindow.xaml.cs:line 33`

Root Cause:

This is caused due to the fact MaterialDesignThemes.Wpf.ResourceDictionaryExtensions in 4.0.0 has changed the properties CurrentThemeKey and ThemeManagerKey to a constant. Also changed their types from GUID to string. This causes MaterialDesignExtensions.Themes.ResourceDictionaryExtensions type initializer to throw up as it Reflects on these items as properties.

Proposed Fix:

Update the MaterialDesignExtensions.Themes.ResourceDictionaryExtensions type initializer to use CurrentThemeKey and ThemeManagerKey as Fields and not properties. To support 3.2.0 fallback to Property read if field is not available.

Also since CurrentThemeKey and ThemeManagerKey are just used as lookup into ResourceDictionary leave them as Object type so it can support both 3.2.0 (Guid) and 4.0.0 (String) of MaterialDesignThemes.Wpf.ResourceDictionaryExtensions class.

spiegelp commented 3 years ago

@ananthk MaterialDesignThemes.WPF introduces some breaking changes. I will tackle them with the next version of MaterialDesignExtensions.

ananthk commented 3 years ago

Awesome. Thanks for the response. Is it possible to add dependency versions in nuspec. So the end users don’t need to find the incompatibility.

Ananth.K


From: Philipp Spiegel @.> Sent: Sunday, March 28, 2021 11:40:26 AM To: spiegelp/MaterialDesignExtensions @.> Cc: Ananth Kasillingam @.>; Mention @.> Subject: Re: [spiegelp/MaterialDesignExtensions] Fail loading MaterialDesignThemes.WPF 4.0.0 (#134)

@ananthkhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fananthk&data=04%7C01%7C%7C4257f5df876e47551c9508d8f218f4f9%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637525536290068074%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=ga0THhDG7HiLr7gSNSL9dRdA2XyvM9gxsal27kmI2%2BE%3D&reserved=0 MaterialDesignThemes.WPF introduces some breaking changes. I will tackle them with the next version of MaterialDesignExtensions.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fspiegelp%2FMaterialDesignExtensions%2Fissues%2F134%23issuecomment-808939924&data=04%7C01%7C%7C4257f5df876e47551c9508d8f218f4f9%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637525536290068074%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=rW4T6d8P7uJhyiYCE%2BD718dzGRjDMw22iuk2g0CdMQw%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAC6ULXIZ2QSGU755AZAMTTTF6A2VANCNFSM4Z2YCN4Q&data=04%7C01%7C%7C4257f5df876e47551c9508d8f218f4f9%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637525536290078070%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=SYNwfLf65LVssppGA6TtxbGKXvMA%2FoJNg6LgGnM%2B1kA%3D&reserved=0.