# ValueConverters.NET **Repository Path**: liuzhga/ValueConverters.NET ## Basic Information - **Project Name**: ValueConverters.NET - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-12-03 - **Last Updated**: 2024-12-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ValueConverters.NET [![Version](https://img.shields.io/nuget/v/ValueConverters.svg)](https://www.nuget.org/packages/ValueConverters) [![Downloads](https://img.shields.io/nuget/dt/ValueConverters.svg)](https://www.nuget.org/packages/ValueConverters) 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: [ https://www.nuget.org/packages/ValueConverters/]( https://www.nuget.org/packages/ValueConverters/) 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. ```xml ``` Apply the converter as a StaticResource: ```xml ``` #### 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. 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: ```cs [DataContract] public enum PartyMode { [EnumMember] [Display(Name = "PartyMode_Off", ResourceType = typeof(PartyModeResources))] Off, // … } ``` 3) 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). 4) Create StringResources.resx for other languages (e.g. StringResources.de.resx) and translate all strings accordingly. Use [Multilingual App Toolkit]( https://visualstudiogallery.msdn.microsoft.com/6dab9154-a7e1-46e4-bbfa-18b5e81df520) for easy localization of the defined string resources. 5) Expose enum property in the ViewModel. ```cs public PartyMode PartyMode { get { return this.partyMode; } set { this.partyMode = value; this.OnPropertyChanged(() => this.PartyMode); } } ``` 6) Bind to enum property in the View and define Converter={StaticResource EnumWrapperConverter}. ```xml