Skip to content

Converters

Marvin E edited this page Sep 8, 2023 · 7 revisions

StringCharLimitConverter

Truncates the end of the binded string until its length is equal to the int specified in the ConverterParameter. Useful for displaying days of the week. Cannot convert back.

In this example:

<ContentPage 
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    x:Class="XCalendarSample.Views.MainPage"
    xmlns:xcConverters="clr-namespace:XCalendar.Converters;assembly=XCalendar">

    <ContentPage.Resources>
        <xcConverters:StringCharLimitConverter x:Key="StringCharLimitConverter"/>
    </ContentPage.Resources>

    <Label Text="{Binding MyString, Converter={StaticResource StringCharLimitConverter}, ConverterParameter=3}"/>

</ContentPage>
  • "Monday" would give "Mon"
  • "Tuesday" would give "Tue"
  • "Wednesday" would give "Wed"
  • "Thu" would give "Thu"
  • "Fr" would give "Fr"

IsNullOrEmptyConverter

Determines if the binded value is null or empty. Returns true if the binded value is null or empty, otherwise, false. Cannot convert back.

LocalizeDayOfWeekAndCharLimitConverter

Localises a DayOfWeek and truncates the result to the specified length.