Changes
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 Example Usage 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!
<syntaxhighlight lang="xml">
<Label Text="{Binding MyValue, Converter={StaticResource Formatter}, ConverterParameter=The Value of my value is \{0\}\, compared to \{1\} and \{2\}!}"/>
</syntaxhighlight>
It's important to note that special characters, like <code><nowiki>{</nowiki></code>, <code><nowiki>}</nowiki></code> and <code><nowiki>,</nowiki></code>, need to be escaped using a <code><nowiki>\</nowiki></code>, else the expression will be wrongly interpreted (and nothing happens)!
The text of the '''ConverterParameter''' will be analyzed, and any occurrance (including duplicates) of <code><nowiki>{0}</nowiki></code>, <code><nowiki>{1}</nowiki></code> and <code><nowiki>{2}</nowiki></code> replaced with the '''binding value''', '''Formatter.Parameter1''' and '''Formatter.Parameter2''' respectively!
Make sure to note, that Xamarin Forms has a native '''[https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/data-binding/string-formatting StringFormat]''' option as well, that is probably way faster than using a converter for it. Furthermore, it supports formatting options!
= Data Source =
Although technically not a converter, the '''SfDataSourceExt''' control is currently on the way of replacing the '''SfDataSourceConverter''', due to improved performance.
The usage is pretty simple: Similar to the converters, it needs to be defined in the '''Page Resources'''. Then, a '''Key''' and '''Expression''', as well as an '''ItemsSource''' have to be defined. Last, but not least, the the converter can be used within the '''ItemsSource''' property of a Syncfusion '''SfListView'''. See the following example:
<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>
<controls:SfDataSourceExt
x:Key="MyDataSource"
ItemsSource="{Binding Children.Items}"
Expression="Item.Content.MetaUID.ToString().ToLower()=="85a50533-3817-4a0b-84cd-615b48b62565" && Item["ORGA_STATUS"]!=100" />
</ResourceDictionary>
</ContentView.Resources>
<sync:SfListView
x:Name="ListView1"
AllowSwiping="True"
ItemSize="60"
ItemTemplate="{StaticResource ChildTemplateSelector}"
ItemsSource="{Binding DisplayItems, Source={StaticResource MyDataSource}}"
LeftSwipeTemplate="{StaticResource SwipeLeftTemplateSelector}"
RightSwipeTemplate="{StaticResource SwipeRightTemplateSelector}"
SelectionMode="None">
</ContentView>
</syntaxhighlight>
Thanks to the given expression, filtering is applied once the data source is evaluated. It's important to have [https://www.advancedinstaller.com/user-guide/xml-escaped-chars.html|XML special characters] correctly escaped, like the example shows.
= List of Available Converters =
'''Two-way''' converters can be used with two-way bindings, e.g. a text-box displaying an editable value. If the value updates in the model, the text-box text changes. If the user edits the value, the value in the model behind also gets updated.
As a clarification'''Value''' refers to the '''Binding Value''', and '''parameter''' to the '''ConverterParameter'''!
{| class="wikitable sortable" style="width:100%"
|-
| SfDataSourceConverter || style="text-align: center;" | ✗ || DataSource (for ListView) || Double || String (Expression) ||
It's an advanced converter used for '''loading items''' and '''applying filters''' on it. It replaces to ''CollectionToViewConverter'' from the WinX.UWP project. The data source can be directly used with a ''[https://help.syncfusion.com/xamarin/sflistview/overview SfListView]''.<br/><br/>'''This converter is obsolete!'''<br/>Use '''SfDataSourceExt''' (see [[#Data Source|Data Source]]) instead!
|-
| StringContainsToBoolConverter || style="text-align: center;" | ✗ || Boolean || String || String ||
Same as the ''StringContainsToBoolConverter'' but with '''inverted output'''.
|-
| StringFormatConverter || style="text-align: center;" | ✗ || String || Object || String || Allows the creation of a '''nicely formatted ''string'' message''', similar to [https://docs.microsoft.com/en-us/dotnet/api/system.string.format C#'s String.Format method].<br/>The value will be interpreted as the <code><nowiki>{0}</nowiki></code> element, and the parameter is the template string (e.g. <code><nowiki>The total count is: {0}!</nowiki></code>. Up to two additional parameters, named ''Parameter1'' and ''Parameter2'', can be defined at the converter declaration. Adding formatting options to the <code><nowiki>{0}</nowiki></code> notation is not possible.<br/><br/>'''Attention''', using the native '''[https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/data-binding/string-formatting StringFormat]''' option is not only faster, but it also offers more customizability of the value!<br/>You might still want to use the ''StringFormatConverter'' in rare cases, though!
|-
| ToStringFormatConverter || style="text-align: center;" | ✗ || String || Double,<br/>Float,<br/>Integer,<br/>DateTime,<br/>String || String || Converts '''primitives''' or '''[https://docs.microsoft.com/en-us/dotnet/api/system.datetime DateTime]''' to string and allows the application of '''[https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings formatting options]''' (as parameter). <br/>Adding a <code>.</code> to the end of the format-parameter allows '''[https://docs.microsoft.com/en-us/dotnet/api/system.math.truncate truncation]''' of all decimal places.