I am converting a WPF
to UWP
and it uses a number of IMultiValueConverters
. I can't find any reference for IMultiValueConverter
. Is it available in UWP
? If not, if there an alternative?
A very simple method for binding to multiple values is to use x:Bind with a function. For example,
<TextBlock Text="{x:Bind local:Helper.FormatName(Id, Name)}" />
or
<TextBlock Text="{x:Bind local:Helper.FormatTotal(ViewModel.SelectedWidget.Cost, ViewModel.Quantity, ViewModel.Bundles)}" />
In both of these examples the function is a static function, but the function can also be defined in the code behind or as part of the view model.
<TextBlock Text="{x:Bind CalculateResult(ViewModel.Widget, ViewModel.Foo)}" />
<TextBlock Text="{x:Bind ViewModel.FormatResult(ViewModel.Widget, ViewModel.Foo)}" />
Rather than passing individual values, you can pass a single object that contains multiple properties.
<TextBlock Text="{x:Bind local:Helper.FormatResult(ViewModel.Widget)}" />
Function binding is very flexible and can often be used in place of a converter, creating simpler, more readable code.
<TextBlock Background="{x:Bind local:Helper.GetColor(ViewModel.Widget)}" />
Function binding can also be used with two way bindings by adding a BindBack function.
<TextBox Text="{x:Bind ViewModel.FormatWidget(ViewModel.Widget), BindBack=ViewModel.UpdateWidget}" />
There is no multiple converter in UWP.
Without Multiple Converter, you can bind to a single property in the ViewModel.
1 That single property should take into account multiple properties from the view model.
Let's call them source properties
2 If any any change is made to a source property, it should raise a PropertyChanged event on the single property.
Regards
There is a very good alternative for this. In the Cimbalino toolkit ( open source on github ) there is a MultiBind behaviour that has been ported to UWP
Details: https://www.pedrolamas.com/2013/05/17/cimbalino-windows-phone-toolkit-multibindingbehavior/ Toolkit code: https://github.com/Cimbalino/Cimbalino-Toolkit
It's also available as nuget, I personally create every UWP app with it, because it has so many great features
© 2022 - 2024 — McMap. All rights reserved.
ListView
whoseItemsSource
is bound to aStuff
property on my VM and I want to say change theForeground
color based no an item in the collection? I don't want my VM exposing color information (normally we would pass in the color from the XAML side into the converter) – Appointment