I’ve been building a bunch of little tools and they each have a .xaml file for their UI. What I want to do now, is create a WPF resource dictionary to be able to unify the styles across all my tools, but I’m running into errors. I have the resource dictionary saved in my main “.extension” folder. Here is a sample of what my UI is doing to try to find that file:
Hopefully this is helpful (better late than never). I found it was easier to have the resource dictionaries (and any embedded images) resolve within the Python class, rather than as part of the XAML. I put the resource dictionary (“WPF_styles.xaml”) in a subfolder called “Resources” and set up the following as a template that I use for all my WPF windows:
This is pretty much a full sample; it should work on its own when you instantiate the class, like so:
ui = MyWindow()
# Resources are resolved during init,
# then setup is called automatically by PyRevit after init.
ui.show()
The only caveat is that you have to update the paths/ lists of paths to the relevant subfolders in your project. I called mine “assets” and “resources” but you can name them anything you like.
And finally, in the xaml file, just make sure the images are defined like so (the “x:name” property is what is used to handle the auto-relinking - the original source gets overwritten, only useful if you’re previewing it in Visual Studio designer):
Ahhh, this is great! The way I had solved this was to create a separate function that does the resources. I would call it before the “ShowDialog()” function. This will save me a step for sure. Thank you!