ValueConverters.MAUI 3.0.26

dotnet add package ValueConverters.MAUI --version 3.0.26
NuGet\Install-Package ValueConverters.MAUI -Version 3.0.26
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ValueConverters.MAUI" Version="3.0.26" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ValueConverters.MAUI --version 3.0.26
#r "nuget: ValueConverters.MAUI, 3.0.26"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ValueConverters.MAUI as a Cake Addin
#addin nuget:?package=ValueConverters.MAUI&version=3.0.26

// Install ValueConverters.MAUI as a Cake Tool
#tool nuget:?package=ValueConverters.MAUI&version=3.0.26


Version Downloads

This library contains a collection of most commonly used implementations of the IValueConverter interface. ValueConverters are used to convert values bound from the view to the view model - and in some cases also backwards.

Download and Install ValueConverters

This library is available on NuGet:

Use the following command to install ValueConverters using NuGet package manager console:

PM> Install-Package ValueConverters

If your target platform is Xamarin.Forms use following NuGet package:

PM> Install-Package ValueConverters.Forms

If your target platform is .NET MAUI use following NuGet package:

PM> Install-Package ValueConverters.MAUI

API Usage

The usage of converters is on all platforms more or less the same:

  • Define the converter in the resources area of the view/page/usercontrol.
  • Use the converter in a binding by referenceing it as a StaticResource.
General Usage of Converters in XAML

Define a converter in the Resources section of a UserControl, Window, Page, etc. Specify options if required.

            <converters:DateTimeConverter x:Key="DateTimeConverter" Format="d" MinValueString="-"/> 

Apply the converter as a StaticResource:

<TextBox Text="{Binding EmployeeDetailViewModel.Birthdate, Converter={StaticResource DateTimeConverter}}"/> 

Using EnumWrapperConverter

EnumWrapperConverter is used to display localized enums. The concept is fairly simple: Enums are annotated with localized string resources and wrapped into EnumWrapper<TEnumType>. The view uses the EnumWrapperConverter to extract the localized string resource from the resx file. Following step-by-step instructions show how to localize and bind a simple enum type in a WPF view:

  1. Define new public enum type and annotate enum values with [Display] attributes:

    public enum PartyMode 
        [Display(Name = "PartyMode_Off", ResourceType = typeof(PartyModeResources))] 

        // … 
  1. Create StringResources.resx and define strings with appropriate keys (e.g. "PartyMode__Off"). Make sure PublicResXFileCodeGenerator is used to generate the .Designer.cs file. (If ResXFileCodeGenerator is used, the resource lookup operations may require more time to complete).

  2. Create StringResources.resx for other languages (e.g. and translate all strings accordingly. Use Multilingual App Toolkit for easy localization of the defined string resources.

  3. Expose enum property in the ViewModel.

        public PartyMode PartyMode 
            get { return this.partyMode; } 

            set { this.partyMode = value; 
                  this.OnPropertyChanged(() => this.PartyMode); } 

  1. Bind to enum property in the View and define Converter={StaticResource EnumWrapperConverter}.

        <Label Content="{Binding PartyMode, Converter={StaticResource EnumWrapperConverter}}" /> 

That’s it. If you want to change the UI language at runtime, don’t forget to call OnPropertyChanged after changing CurrentUICulture. There is a WPF sample app available.

Converter Culture

Value converters are culture-aware. Both the Convert and ConvertBack methods have a culture parameter that indicates the cultural information. If cultural information is irrelevant to the conversion, then you can ignore that parameter in your custom converter.

By default, the culture parameter is provided by the underlaying platform. If you want to override the provided culture, use the property PreferredCulture. You can select from one of the following override behaviors:

  • PreferredCulture.ConverterCulture: Default, uses the converter culture provided by the underlying platform.
  • ConverterCulture.CurrentCulture: Overrides the default converter culture with CultureInfo.CurrentCulture.
  • ConverterCulture.CurrentUICulture: Overrides the default converter culture with CultureInfo.CurrentUICulture.

This is particularly helpful in WPF applications, since it is a known/unresolved bug that the provided culture parameter does not update when CultureInfo.CurrentCulture or CultureInfo.CurrentUICulture is updated. Use ValueConvertersConfig.DefaultPreferredCulture to configure the default converter culture for all converters.


ValueConverters.NET is Copyright © 2021 Thomas Galliker. Free for non-commercial use. For commercial use please contact the author.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-android31.0 is compatible.  net6.0-ios was computed.  net6.0-ios16.1 is compatible.  net6.0-maccatalyst was computed.  net6.0-maccatalyst16.1 is compatible.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net6.0-windows10.0.19041 is compatible.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.26 397 1/31/2023
3.0.24-pre 130 12/31/2022
3.0.23-pre 125 12/31/2022
3.0.22-pre 134 12/31/2022
3.0.21-pre 122 12/31/2022
3.0.20-pre 123 12/31/2022
3.0.18-pre 124 12/31/2022
3.0.15-pre 128 12/31/2022