How to make all text upper case / capital?

Viewed 87171

I want all texts in TextBlock, Label, MenuItem.Header to be displayed in upper case. The strings are taken from a ResourceDictionary e.g.:

<TextBlock Text="{StaticResource String1}"/>
<MenuItem Header="{StaticResource MenuItemDoThisAndThat}"/>

etc. (also for Label and other controls)

I cannot use a value converter because there is no binding. I don't want to make the strings upper case in the dictionary itself.

8 Answers
    public class StaticResourceToUpperExtension : StaticResourceExtension
    {
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            var resource = base.ProvideValue(serviceProvider);
            if (resource is string str)
                return str.ToUpper();
            return resource;
        }

        public StaticResourceToUpperExtension() : base() { }
        public StaticResourceToUpperExtension(object resourceKey) : base(resourceKey) { }

    }
    <Grid>
        <FrameworkElement.Resources>
            <sys:String x:Key="String1">any text</sys:String>
        </FrameworkElement.Resources>
        <TextBlock Text="{local:StaticResourceToUpper String1}"/>
    </Grid>
Related