I have an application that has one window and a dozen pages. I have a class of bindable properties I want to use for bindings on several pages. I also need to access them often in the code behind.
I am not totally satisfied with my current solution. I instantiate the class of bindables as public static. I set up another routine as public static that declares the bindables as datacontext to the window and pages I need. This way they all share the same instance.
public class dcx // DataContext, bindable parameters
{
public static Bindables myBindables = new Bindables();
public static void InitializeDataContext()
{
win.Main.DataContext = myBindables;
pages.page1.DataContext = myBindables;
pages.page2.DataContext = myBindables;
pages.page3.DataContext = myBindables;
}
}
One of the drawbacks to this is that at design time none of the parameters are available. It makes design much more difficult. I guess I could declare the datacontext with d: and then at runtime it would get overridden.
It just all seems like there should be a better way.