Changes

Converters In Xamarin

1,702 bytes added, 13:42, 7 August 2019
</syntaxhighlight>
The key ''NullToBool'' makes this converter accessible from the customizing in this page.
== Definition With Properties ==
In the following example, which is the same example from above, the '''StringFormatConverter''' will be additionally defined. To add more formatting possibilities, it has two extra properties, which need to be prefilled during initialization. Henceforth, these properties can be prefilled with static values or with static references.
<syntaxhighlight lang="xml">
<ContentView x:Class="UBIK.CPL.Resources.UBIKChildArea"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:converters="clr-namespace:UBIK.CPL.Converters;assembly=UBIK.CPL">
<ContentView.Resources>
<ResourceDictionary>
<converters:NullToBoolConverter x:Key="NullToBool" />
<converters:StringFormatConverter x:Key="Formatter" Parameter1="5" Parameter2="{Binding Children.Items.Count}" />
</ResourceDictionary>
</ContentView.Resources>
 
<!-- Cuztomizing -->
 
</ContentView>
</syntaxhighlight>
Whereever this converter is used within the file it was defined in, ''Formatter'' will always have its ''Parameter1'' set to ''5'' and its ''Parameter2'' to the number of children of the currently viewed UBIK object. If this behavior is not intended, consider defining another ''StringFormatConverter'' with a '''different Key''' in the same way as shown above.<br/>
See below to find out how to use this converter!
= Usage =
A converter can only be used in conjunction with a <code>{Binding}</code>. The following is an easy example, showing how the ''NullToBool'' converter, defined above, can be used.
</syntaxhighlight>
If '''MyBindableProperty''' is ''null'' or an empty string, the converter will return '''true''', making the Label visible!
 
== 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>.
== 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'''.
 
= Examples =
This section shows some possible applications of these converters.
 
== StringFormatConverter ==
This converter can take up to two additional parameters during definition. Please see [[#Definition With Properties|Definition With Properties]] for more information!
= List of Available Converters =
187
edits