I have a Python Script in combination with a WPF-file (XAML).
In the XAML-file I have many ComboBoxes that have identical ItemsSources. Is there a way to centralize the inputs so I don’t have to repeat them so many times.
Now it looks something like this:
self.Facade1a.ItemsSource = viewsElevDict
self.Facade1b.ItemsSource = viewsElevDict
self.Facade1c.ItemsSource = viewsElevDict
self.Facade1d.ItemsSource = viewsElevDict
Seems really inefficient, so any help on how to properly do this is welcome!
PS: I have googled ResourceDictionaries, but almost no information on Python is available online.
I assume you gave up on this, but I would like to point you to these two articles that uses XAML property bindings to do what you want.
To be honest, for this specific case it is just moving the assignment of the ItemsSource in the XAML and write much more python code.
You could define a binding as a resource, but it involves creating a subclass of StaticResourceExtension to properly get the values, and then again, you just moved the binding but you have to set it to each combobox.
Nevermind the links I gave you for the basic property bindings, Ehsan already did a great job and bundled in the
pyrevit.forms module the
Reactive classes, and the
@reactive decorator (to use in place of the
@property decorator) to remove the boilerplate code.
But, like I said, all of this only moves the problem to another location.