如何通过XAML将WPF中的小写转换为大写?

Cha*_*u A 3 c# wpf xaml textbox lowercase

我尝试在WPF中通过XAML将大写转换为小写,如下所示:

<TextBox Height="86" CharacterCasing="Upper"/>
Run Code Online (Sandbox Code Playgroud)

我想实现用同样的场景TextBlock,LabelButton.

我该怎么做?

Dav*_*ton 9

您应该使用值转换器:

public class ToUpperValueConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        var str = value as string;
        return string.IsNullOrEmpty(str) ? string.Empty : str.ToUpper();
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)