Often when developing Revit plugins, WPF is used to create windows. Here I referenced the MaterialDesignThemes component, and I will record the corresponding steps and issues in this article.

Usage

Installation

  1. Search for MaterialDesignThemes directly from nuget and install it.
![Image Description](https://cdn.bimath.com/blog/pg/Snipaste_2026-01-04_16-55-22.png)
2. Add resources
1
2
3
4
5
6
7
8
9
10
11
12
<Window.Resources>
<ResourceDictionary>
<viewmodel:ObjectConvert x:Key="ObjectConverter" ></viewmodel:ObjectConvert>
<ResourceDictionary.MergedDictionaries>
<materialDesign:BundledTheme
BaseTheme="Light"
PrimaryColor="DeepPurple"
SecondaryColor="Lime" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
## Issues If you are using a multi-version automatic adaptation framework and referencing the latest version `4.60` component, even if adapted in a high framework version, it will report an error `xamlParseException ---- DllNotFound`. At this time, modify the component package to `4.5.0` to adapt to the 2016 version of the framework to solve it.

Running

If you use AddinManager directly for debugging, you may not find problems, and all components will run normally. When we use the addin file to officially add, it will report an error xamlParseException ---- DllNotFound. Here are several solutions:

[] Revit Secondary Development Could not load file or assembly
[x] WPF, Could not load file or assembly
[] https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/issues/427
[] https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/issues/427

There are four articles above. The first method is to initialize the class in the material component to force the program to retrieve the dll under the path to load the file, but it still fails in Revit. The third and fourth are similar problems, open source author responses, you can refer to them.

Solution

If you use the MVVM pattern, you can get the MainViewModel in the StartUp class and reference the materialTheme.wpf dll file, and unify the previously encountered dll files with load problems.

1
AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public static Assembly AssemblyResolve(object sender, ResolveEventArgs args)
{
var assName = new AssemblyName(args.Name).FullName;
try
{
if (assName.Contains("WPF_CaptureShot") && !assName.Contains("resources"))
{
string file = Path.GetDirectoryName(typeof(MakeDataRevitCommand).Assembly.Location) + "\\" + assName.Split(',')[0] + ".dll";

byte[] buff = System.IO.File.ReadAllBytes(file);
var da = Assembly.Load(buff);
return da;
}
else if (assName.Contains("MaterialDesignThemes.Wpf") && !assName.Contains("resources"))
{
string pathLoc = Assembly.GetExecutingAssembly().Location;
FileInfo finfo = new FileInfo(pathLoc);
var pathDir = finfo.DirectoryName;
var load = Assembly.LoadFrom($"{pathDir}\\MaterialDesignThemes.Wpf.dll");
Assembly.LoadFrom($"{pathDir}\\MaterialDesignColors.dll");
return load;
}
else if (assName.Contains(".resources"))
{

return null;
}
else
{
throw new DllNotFoundException("BIMCooperative" + assName);
}

}
catch (Exception ex)
{
throw new DllNotFoundException(assName);//Otherwise throw loading failure exception
}
}