4

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:

  1. Is there a reason the resources would fail to resolve in the XAML designer given the way I have defined them in App.xaml (per the developer guide: https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/wiki/Getting-Started)?
  2. How can I find out the "absolute pack URI" to use for the source for my resource dictionaries?
user3342256
  • 1,238
  • 4
  • 21
  • 35

2 Answers2

1

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".

FastDev
  • 67
  • 7
0

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
Welcor
  • 2,431
  • 21
  • 32