Jump to: navigation, search

Changes


Converters In Xamarin

1,684 bytes added, 13:15, 6 August 2019
| BooleanInvertConverter || style="text-align: center;" | ✓ || Interprets and converts a '''boolean''' into its '''inverted value'''. If the value cannot be interpreted, ''false'' is returned.
|-
| BooleanToFontAttributeConverter || style="text-align: center;" | ✗ || Converts a '''boolean''' into a '''[[https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.fontattributes?view=xamarin-forms font attribute]]''' value. In detail, if the value is ''true'', the parameter is interpreted (''Bold'', ''Italic'', ''None'') and returned. The default returned font-attribute is ''None''.
|-
| ByteToImageSourceValueConverter || style="text-align: center;" | ✗ || Converts a '''byte stream''' value into an '''image source'''.
| ChildAreaTemplateConverter || style="text-align: center;" | ✗ || Returns a '''ChildAreaTemplate''' from a '''ContentViewModel''' or ''null'' if the ViewModel cannot be interpreted.
|-
| ChildItemSelectionModeToSfListViewSelectionModeConverter || style="text-align: center;" | ✓ || Converts a '''ChildItemSelectionMode''' to '''[[https://help.syncfusion.com/cr/cref_files/xamarin/Syncfusion.SfListView.XForms~Syncfusion.ListView.XForms.SfListView~SelectionMode.html Syncfusion's ListViewSelectionMode]]'''. Default is "Single".
|-
| ClassificationToBoolConverter || style="text-align: center;" | ✗ || Returns a '''boolean''' indicating whether the given '''ContentViewModel''' is successfully classified.
| StringContainsToInvertedBoolConverter || style="text-align: center;" | ✗ || Same as the ''StringContainsToBoolConverter'' but with '''inverted output'''.
|-
| StringFormatConverter || style="text-align: center;" | ✗ || 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.
|-
| ToStringFormatConverter || style="text-align: center;" | ✗ || 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.
| DataTemplateItemsPanelConverter || style="text-align: center;" | ✗ || Chooses what '''ItemPanelTemplate''' to return. Having a parameter with the content "Small" returns the small item template selector.
|}
=== Definition ===In Xamarin, before converters can be used, they need to be defined in the page's ''Resources'' tag. Make sure to include the <code>UBIK.CPL.Converters</code> namespace in the namespace definitions!The following example shows how the <code>NullToBoolConverter</code> can be defined:<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" /> </ResourceDictionary> </ContentView.Resources>  <!-- Cuztomizing --> </ContentView></syntaxhighlight>The key ''NullToBool'' makes this converter accessible from the customizing in this page.===Usage===This description 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 lang="xml"><Label Text="My Text" IsVisible="{Binding MyBindableProperty, Converter={StaticResource NullToBool}}"/></syntaxhighlight>If '''MyBindableProperty''' is ''null'' or an empty string, the converter will follow soonreturn '''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>.
187
edits