How to switch WPF Theme in a RhinoPlugin?

RhinoPlugin is a class library project and cannot switch styles by adding a resource dictionary in App.xaml like a regular application. Is there an appropriate method to do this?
like this

Application.Current.Resources.MergedDictionaries[0].Source =
	Application.Current.Resources.MergedDictionaries[0].Source
	.ToString() == ThemeDark ? new Uri(ThemeDefault) : new Uri(ThemeDark);

private const string ThemeDark = "pack://application:,,,/******;component/Style/Dark.xaml";
private const string ThemeDefault = "pack://application:,,,/******;component/Style/Default.xaml";```

If working with MahApps: MahApps.Metro Themes

Hi!
The RhinoPlugin project does not have an App.xaml file, and it cannot be added. Therefore, this method is not available.

1 Like

You can dynamically merge in any Xaml Resources that your plugin needs during the OnLoad() method for your plugin.

For instance, we apply specific styles for our application, and override some existing styles of Rhino when our plugin loads, using a static helper class similar to the following:

The first step is to add the Xaml resource to your plugin’s solution, and then use the relative Uri to map to the resource’s location.

Next you access Rhino’s Application Resources, and merge in the resource.

Now your WPF UI will have access to those resources. Just make sure that you do these before any of your UI is shown.