Menu

Skip to content
Sytone's Ramblings
  • Home
  • About

Sytone's Ramblings

the occasional posts of a guy who plays with technology

WPF Converter: CaseConverter

Posted on August 29, 2010 by Sytone

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.

<TextBlock Text="{Binding Title, Converter={StaticResource CaseConverter}}"/>

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”

<local:CaseConverter x:Key="CaseConverter" />

This is the class, short and sweet.

    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;
        }
    }

Share this:

  • Email
  • Print
  • Reddit
  • Twitter
  • Pocket
  • Pinterest
Posted in CSharp | Tagged Binding c# XAML | 3 Comments

3 thoughts on “<span>WPF Converter: CaseConverter</span>”

  1. afro

    3/28/11
    02:39
    2011/03/28
    02:39

    afro says:

    don’t you want return null to be
    return value;

  2. Sytone

    5/18/11
    14:57
    2011/05/18
    14:57

    Sytone says:

    Yes, you are correct. I only used it in a label so had no need to return the value. I have updated it so it should work in other fields now.  

  3. Zayanimahjoub

    6/14/12
    08:01
    2012/06/14
    08:01

    Zayanimahjoub says:

    How to use it on an UseControl ??

Leave a Reply Cancel reply

Tags

API autohotkey Binding c# cache Content Deployment development engineering forge Games General Gnomoria hack Home Assistant Home Automation hosting ISO ISY JSON libraries Microsoft Microsoft Flow minecraft MoCA mod network openhab outlook paper PowerShell REST Security SharePoint site SQL toodledo troubleshooting Tweak Visual Studio Visual Studio Code windows 7 Windows 8 Windows Phone winkhub XAML

Recent Posts

  • iPhone hotspot issues? Getting it to work with windows.
  • Getting a DietPi image running on Hyper-V
  • Getting HP Officejet Pro 8620 scan to network working…
  • Developing Home Assistant on Windows using the Subsystem for Linux
  • Using Microsoft Flow with Home Assistant

Recent Comments

  • Shrabean on Automating OneNote with AutoHotKey to be a Journal V1.1
  • danbutter on Integrating ISY into OpenHAB
  • Sytone on Integrating ISY into OpenHAB
  • rick Sumter on Integrating ISY into OpenHAB
  • Sytone on Automating OneNote with AutoHotKey to be a Journal V1.1

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
Proudly powered by WordPress
Theme: Flint by Star Verte LLC
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.