I have a UserData class instance containing a user’s settings and other information. Since it has settings for different parts of the application, it should be easily accessible anywhere. For this reason it’s a static property on the App class.
I need a menu where some checkable items are two-way bound to some of the (Boolean, obviously) settings so that the menu item always shows if the setting is on/off and can be used to toggle it.
Since the UserData instance is a static property, it doesn’t natively work with two-way binding.
What would be the best way to solve this situation? Is there a way that doesn’t require instantiating throwaway objects or manually creating a dependency property for each and every setting individually?
You can’t bind directly to the static property itself, but you can use the value of a static property as a binding source and then bind to its properties just as you would any other object instance. There are a few variations of what your Binding will look like but if you want to do a bunch of properties on the same object you can use the static object as a DataContext (which is One-Way) and then normal bindings on the MenuItems: