Bind to multiple properties in UWP

In a C # project, I have a complex model that uses many classes nested in lists and dictionaries (for example, object A has a list of instances of B that have a dictionary, where values โ€‹โ€‹are instances of C ). On one of my pages this model is shown in a complex form using nested ItemsControl s.

In addition, there is a Settings class that stores user settings, some of which are tied to checkboxes on the page.

Now I want to bind the properties of some controls in the DataTemplate to a combination of model properties and customization. For example, suppose C has the IsBoring property, and there are Settings.HideBoringStuff settings. I want to bind the visibility of a TextBlock representing C to an obvious combination of these properties.

I don't know how to do this without ugly hacks. Here are some of my ideas and why they do not work:

  • Use MultiBinding , which is specifically designed for this. However, MultiBinding not available in UWP projects.

  • Bind to several properties of a page that implements logic in its getters and setters. This does not work because I'm inside a DataTemplate , so I need several independent copies of this logic.

  • Use Converter to convert a model property by passing ConverterProperty as a parameter. However, ConverterProperty n o DependencyProperty and therefore cannot be bound.

  • Create the necessary properties directly in model - Settings anyway. This seems very ugly as I will mix unnecessary dependencies and consider the logic in my model.

  • Create separate classes that wrap model classes, also save the Settings object for use, and then offer combined properties. It also seems very ugly, since I will need to replicate the entire hierarchy of model objects. (In the ViewA example, a list of ViewB s should be presented, each of which has a dictionary, where the values โ€‹โ€‹correspond to ViewC s.)

  • Wait for Microsoft to bring MultiBinding back. Unfortunately, I lack the necessary optimism.

What are the clean ways to do this in a UWP app?

+5
source share
1 answer

It is true that Multibinding was not around the new win dev stacks. BUT the Cimbalino Toolkit has had this since the start of wp8 days. It also has a UWP port.

So maybe try this!

Blogpost from the first days explaining the use: https://www.pedrolamas.com/2013/05/17/cimbalino-windows-phone-toolkit-multibindingbehavior/ Cimbalino is obtained via nuget and is available on Github here https: // github. com / Cimbalino / Cimbalino-Toolkit

+4
source

Source: https://habr.com/ru/post/1237787/


All Articles