ValueConverters.Annotations
3.1.14-pre
See the version list below for details.
dotnet add package ValueConverters.Annotations --version 3.1.14-pre
NuGet\Install-Package ValueConverters.Annotations -Version 3.1.14-pre
<PackageReference Include="ValueConverters.Annotations" Version="3.1.14-pre" />
paket add ValueConverters.Annotations --version 3.1.14-pre
#r "nuget: ValueConverters.Annotations, 3.1.14-pre"
// Install ValueConverters.Annotations as a Cake Addin #addin nuget:?package=ValueConverters.Annotations&version=3.1.14-pre&prerelease // Install ValueConverters.Annotations as a Cake Tool #tool nuget:?package=ValueConverters.Annotations&version=3.1.14-pre&prerelease
ValueConverters.NET
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/
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.
<UserControl.Resources>
<ResourceDictionary>
<converters:DateTimeConverter x:Key="DateTimeConverter" Format="d" MinValueString="-"/>
</ResourceDictionary>
</UserControl.Resources>
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:
- Define new public enum type and annotate enum values with [Display] attributes:
[DataContract]
public enum PartyMode
{
[EnumMember]
[Display(Name = "PartyMode_Off", ResourceType = typeof(PartyModeResources))]
Off,
// …
}
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).
Create StringResources.resx for other languages (e.g. StringResources.de.resx) and translate all strings accordingly. Use Multilingual App Toolkit for easy localization of the defined string resources.
Expose enum property in the ViewModel.
public PartyMode PartyMode
{
get { return this.partyMode; }
set { this.partyMode = value;
this.OnPropertyChanged(() => this.PartyMode); }
}
- 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.
Links
System.Windows.Data.IValueConverter Interface https://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter(v=vs.110).aspx
Windows.UI.Xaml.Data.IValueConverter interface: https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.data.ivalueconverter
License
ValueConverters.NET is Copyright © 2021 Thomas Galliker. Free for non-commercial use. For commercial use please contact the author.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. 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. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.0 is compatible. netstandard1.1 was computed. netstandard1.2 was computed. netstandard1.3 was computed. netstandard1.4 is compatible. netstandard1.5 was computed. netstandard1.6 is compatible. netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net45 was computed. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 is compatible. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Windows Phone | wp8 was computed. wp81 was computed. wpa81 was computed. |
Windows Store | netcore was computed. netcore45 was computed. netcore451 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.8
- No dependencies.
-
.NETStandard 1.0
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.4
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.6
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 2.0
- No dependencies.
NuGet packages (3)
Showing the top 3 NuGet packages that depend on ValueConverters.Annotations:
Package | Downloads |
---|---|
ValueConverters
A collection of commonly used IValueConverters for WPF applications. |
|
ValueConverters.Forms
A collection of commonly used IValueConverters for Xamarin.Forms applications. |
|
ValueConverters.MAUI
IValueConverters for .NET MAUI |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.1.22 | 1,065 | 9/26/2024 |
3.1.14-pre | 122 | 9/26/2024 |
3.1.11-pre | 171 | 9/2/2024 |
3.1.8-pre | 164 | 9/2/2024 |
3.1.7-pre | 174 | 8/30/2024 |
3.0.26 | 8,646 | 1/31/2023 |
3.0.24-pre | 653 | 12/31/2022 |
3.0.23-pre | 614 | 12/31/2022 |
3.0.22-pre | 598 | 12/31/2022 |
3.0.21-pre | 604 | 12/31/2022 |
3.0.20-pre | 618 | 12/31/2022 |
3.0.18-pre | 623 | 12/31/2022 |
3.0.15-pre | 565 | 12/31/2022 |
2.3.9-pre | 586 | 12/29/2022 |
2.3.6-pre | 866 | 11/10/2021 |
2.2.13-pre | 785 | 11/3/2021 |
2.2.10 | 32,480 | 11/2/2021 |
2.2.8-pre | 772 | 11/2/2021 |
2.2.7-pre | 776 | 11/1/2021 |
2.2.1-pre | 778 | 11/1/2021 |
2.1.21120.1-pre | 789 | 4/30/2021 |
2.1.21074.1-pre | 809 | 3/15/2021 |
2.1.20351.1-pre | 896 | 12/16/2020 |
2.1.20334.2-pre | 851 | 11/29/2020 |
2.1.20334.1-pre | 850 | 11/29/2020 |
2.0.20198.2-pre | 931 | 7/16/2020 |
2.0.20011.1 | 23,171 | 6/3/2020 |
2.0.19326.5-pre | 971 | 6/3/2020 |
2.0.19169.1-pre | 1,376 | 6/18/2019 |
2.0.19108.2-pre | 1,426 | 4/18/2019 |
2.0.19108.1-pre | 1,085 | 4/18/2019 |
2.0.19091.2 | 6,899 | 4/1/2019 |
2.0.19088.1-pre | 1,102 | 3/29/2019 |
2.0.19076.1 | 1,497 | 3/17/2019 |
2.0.19034.3-pre | 1,152 | 2/3/2019 |
2.0.19034.1-pre | 1,120 | 2/3/2019 |
2.0.19005.5-pre | 1,038 | 1/5/2019 |
2.0.19005.4-pre | 1,132 | 1/5/2019 |
2.0.19004.1-pre | 1,179 | 1/4/2019 |
2.0.18339.13-pre | 1,094 | 12/5/2018 |
1.0.0
- Initial release