Reputation: 1002
I've been using MahApps.Metro from NuGet for a while without any issues. However, recently I had a few issues with NuGet packages needing to be reinstalled.
In the end, I uninstalled all of the NuGet packages I needed and reinstalled them. As far as I can tell, everything works correctly now except that when I try to start the application, it immediately throws the above exception:
System.Windows.Markup.XamlParseException: ''Set property 'System.Windows.ResourceDictionary.Source' threw an exception.' Line number '34' and line position '18'.'
Inner Exception
IOException: Cannot locate resource 'styles/colors.xaml'.
And if I check those specified lines, it is this <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
.
My App.xaml looks like this:
<Application.Resources>
<ResourceDictionary>
<!-- Some other stuff is here -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<!-- Bunch of other stuff here -->
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
I have tried various things from other similar questions:
StartupUri
is correctAssembly name
and Default namespace
are different (and have always been)I'm completely at a loss as to what try next...
Upvotes: 6
Views: 5113
Reputation: 23869
Since you most likely used the latest NuGet
package of MahApps.Metro v2.0 you got these errors. As you mentioned we need to follow official Migration to v2.0 guide. Following steps helped me resolve the issue that may help some other readers of this post who are encountering the similar issues:
Remove the tag <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
Replace tags such as
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Green.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />`
with
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Green.xaml" />`
In the tag <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedTabControl.xaml" />
remove the word Animated
If there are any other tags raising error, please refer to the above link. I used that link to solve above issues.
Upvotes: 11
Reputation: 1002
The one thing I hadn't tried was using an older version... And yep version 2.0.0 of MahApps.Metro changed how themes were done. Using version 1.6.5 fixes the issue or you need to follow the migration guide here: https://mahapps.com/docs/guides/migration-to-v2.0
Upvotes: 4