In a C# project, I have a complex model using lots of classes nested in lists and dictionaries (e.g. object A has a list of instances of B, which have a dictionary where values are instances of C).
In one of my pages, this model is shown in a complex view using nested ItemsControls.
In addition, there is a Settings class which stores user preferences, some of which are bound to checkboxes on the page.
Now, I want to bind properties of some controls within the DataTemplates to a combination of a model property and a setting. For example, let's say that C has a property IsBoring, and there is a settings Settings.HideBoringStuff. I want to bind the visibility of the TextBlock representing C to the obvious combination of these properties.
I have no idea how to do that without ugly hacks. Here are a few of my ideas and why they don't work:
Use a
MultiBinding, which is specifically designed to do this. However,MultiBindingis not available in UWP projects.Bind to multiple properties on the page that implement the logic in their getters and setters. This doesn't work because I'm inside a
DataTemplate, so I need multiple independent copies of this logic.Use a
Converterto convert the model property, passing in the setting as aConverterProperty. However, theConverterPropertyis noDependencyPropertyand therefore cannot be bound.Build the needed properties right into the model –
Settingsis a singleton anyway. This feels really ugly, as I'd be mixing unnecessary dependencies and view logic into my model.Build separate classes that wrap the model classes, also store the
Settingsobject to use, and then offer the combined properties. This feels really ugly too, as I'd need to replicate the whole object hierarchy of the model. (In the example,ViewAneeds to offer a list ofViewBs, each of which have a dictionary where the values are the correspondingViewCs.)Wait for Microsoft to bring
MultiBindingback. Unluckily, I'm lacking the required optimism.
Which are clean ways to do this in a UWP application?