WPF Converter: CaseConverter
Case Converter was made when I wanted the text to display in a WPF UI in upper case. Probably not the best class name, but anyway. To get the code and install read on. Make any UI string uppercase. Once you have registered the resource and created the class just use the converter in the element you want converted.
xml code snippet start
<TextBlock Text="{Binding Title, Converter={StaticResource CaseConverter}}"/>xml code snippet end
Add the following element to the XAML, usually in Window.Resources and ensure that you have registered your namespace for local to the namespace of your application. e.g. xmlns:local=“clr-namespace:ExampleApp”
xml code snippet start
<local:CaseConverter x:Key="CaseConverter" />xml code snippet end
This is the class, short and sweet.
csharp code snippet start
public class CaseConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string text = value as string;
if(text != null)
{
return text.ToUpper(culture);
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value;
}
}
```csharp code snippet end