I have a specific TextBlock in a WPF application. I need to make the text Uppercase for that specifc TextBlock.
Trying with the following code I get this error:
{"'TextUpperCase' is not a valid value for property 'Style'."}
Any idea how to solve it?
<Style x:Key="TextUpperCase" TargetType="{x:Type TextBox}">
<Setter Property="CharacterCasing" Value="Upper"/>
</Style>
<TextBlock
x:Name="ShopNameTextBlock"
TextWrapping="Wrap"
Text="{Binding Description, FallbackValue=Shop name}"
Style="TextUpperCase"
VerticalAlignment="Center"
FontFamily="/GateeClientWPF;component/Fonts/#Letter Gothic L"
FontSize="45"
Grid.ColumnSpan="2"
Margin="0,60,0,0"
FontWeight="Medium"
TextAlignment="Center"
Foreground="Black"
/>
CharacterCasing
is not valid property for TextBlock
, it's for TextBox
.
You can have IValueConverter and use it with your binding which will convert text to Upper.
Declare Converter:
public class ToUpperValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
CultureInfo culture)
{
if (value is string)
{
return value.ToString().ToUpper();
}
return String.Empty;
}
public object ConvertBack(object value, Type targetType, object parameter,
CultureInfo culture)
{
return Binding.DoNothing;
}
}
Now, add a reference of your converter in XAML and use like this:
<TextBlock Text="{Binding Description,
Converter={StaticResource ToUpperValueConverter}}"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With