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.
This does not strictly answer the question but does provide a trick to cause the same effect.
I believe many finding their way here are looking how to do this with a style. TextBlock is a bit tricky here because it is not a Control but a FrameworkElement and therefore you can not define a Template to do the trick.
The need to use all uppercase text is most likely for headings or something like that where use of Label is justified. My solution was:
Note that this does disable some of the default behavior of Label, and works only for text, so I would not define this as default (no one probably wants all labels uppercase anyway). And of course you must use Label instead of TextBlock when you need this style. Also I would not use this inside of other templates, but only strictly as a topic style.
You still can use a converter, just set the textvalue in the source of the binding :
You can case all input into TextBox controls with the following property:
To apply to all TextBox controls in the entire application create a style for all TextBox controls:
To complete Peter's answer (my edit has been rejected), you can use a converter like this:
C#:
XAML:
I created an attached property and converter for this. You probably already have the converter, so replace my reference to CaseConverter to whatever implementation you have.
The attached property is just a boolean that you set if you want it to be uppercase (you could obviously extend this to instead be an enumerable for a selection of styles). When the property changes, it rebinds the TextBlock's Text property as needed, adding in the converter.
A little more work might need to be done when the property is already bound - my solution assumes it's a simple Path binding. But it may need to also duplicate the source, etc. However I felt this example is enough to get my point across.
Here's the attached property:
I think this will work for you
For font capitals enumerations https://msdn.microsoft.com/en-us/library/system.windows.fontcapitals(v=vs.110).aspx