Reputation: 1290
I am using the MaterialDesign for XAML package in WPF. When I run my application, all styles and controls are rendered as expected. However in the XAML designer I have dozes of errors such as "The resource 'MaterialDesignFlatButton' could not be resolved." Example of a line that is throwing that error:
<Button Style="{StaticResource MaterialDesignFlatButton}" IsDefault="True" Margin="0 8 8 0" ...
My app.xaml contents is as follows:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.LightBlue.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
I have attempted the top solution proposed on The resource "x" could not be resolved. but that causes the project to fail to run (I believe I am not using the correct pathing when attempting to use the proposed "absolute pack URI"). So I have two questions at this point:
Upvotes: 6
Views: 8585
Reputation: 43
Keep in mind this does not work anymore for 5.0.0 . The Defaults theme does not exist under that name. You need to use another one (or switch back to 4.9).
https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/issues/3485
In documentation the Default is still used. The AIs are using the definitions from the documentation, so they will give you a wrong Source path.
Im using:
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesign2.Defaults.xaml" />
Upvotes: 3
Reputation: 516
In the past, I had problems like this. The error causes are as follow.
1. Setup and setting config
About this, please check the github and material design homepage.
2. Build and Compiler problem
About this, users may set the "Platform Target" as "x64". That can invoke errors because material designer tool use "x32" compiler, so please use "any cpu" or "x32".
Upvotes: 1
Reputation: 3113
I had this problem with the flat accent button, while every other button style worked. I added the resource for buttons, then the error was gone. Then I removed the button resource... and the error was still gone.
https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/wiki/FAQ
Exception: Cannot find resource named 'MaterialDesign...'
This error typically comes when you have a static resource referencing one of the material design styles, and have not included the appropriate resource dictionary that contains the style. Try the following:
- Ensure that you have loaded all of the default material design styles in your App.xaml. You can find directions for this in the Getting Started guide.
- Ensure you have referenced the control specific resource dictionary that contains the style. The path for this is resource dictionary should be .xaml" />. For example, if you were trying to reference the MaterialDesignFloatingActionMiniButton style for a button, the resource dictionary source would be: . Typically these inclusions are done at root of your Window, User Control, or Template. You can find the full list of the resource dictionaries here
Upvotes: 0