Jump to: navigation, search

Changes


Converters In Xamarin

885 bytes added, 14:09, 6 August 2019
=== Parameter ===
Some converters accept a '''ConverterParameter''', that passes additional information. Closely read the description of the available converters to find out which accept or even require a parameter to work properly. In Ubik, some converters accept a string parameter, consisting of multiple individual parameters separated by <code>|</code>.
 
An example of this behavior is the '''ContainsToBoolConverter''', which checks if the current value is contained within a collection of values (passed as the ''parameter''):
<syntaxhighlight lang="xml">
<Label Text="My Text" IsVisible="{Binding MyValue, Converter={StaticResource ContainsToBool}, ConverterParameter=1|2|3|4|5|6|7|8|9}"/>
</syntaxhighlight>
The label will only be visible if the ''MyValue'' property (which is expected to parse as an Integer in this example) is one of the values of the parameter.<br/>
Again, to get the converter working, don't forget to define it in the page's resources!
 
=== FallbackValue ===
In some rare cases, a converter might not return anything desired (like ''null'') if some condition doesn't work out as it should (e.g. ''value'' is ''null''). To still be able to get a usable return value, it's possible to define a '''FallbackValue'''.
187
edits