使用StringFormat和大写转换器绑定表达式?

ton*_*y19 1 data-binding wpf string-formatting valueconverter

我有一个TextBlock文本绑定生活自动收报机(通过System.Date.Now),该绑定包含一个ValueConverter应该将字符串转换为大写的.但是,字符串不会产生大写字母(结果就好像转换器不在那里).如何将绑定结果设为大写?

<TextBlock 
        Text="{Binding Now,
                       Source={StaticResource ticker},  
                       StringFormat={}{0:dddd\, MMMM d}, 
                       Converter={StaticResource CaseConverter}}" />
Run Code Online (Sandbox Code Playgroud)

Phi*_*hil 7

HB是对的.你需要一个更好的转换器:

    <TextBlock Text="{Binding Now, Source={StaticResource ticker}, Converter={StaticResource UpperCaseDateConverter}, ConverterParameter='dddd, MMMM d'}" />
Run Code Online (Sandbox Code Playgroud)

转换器:

public class UpperCaseDateConverter : IValueConverter
{
    #region Implementation of IValueConverter

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return ((DateTime)value).ToString((string)parameter).ToUpperInvariant();
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }

    #endregion
}
Run Code Online (Sandbox Code Playgroud)