Wpf Binding Stringformat to show only first character
问题 Is there any way so that i can show only first character of a Bound string on a textblock..? For eg;If i Bind 'Male', my textblock should only show 'M'..... 回答1: You might use a value converter to return a string prefix: class PrefixValueConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string s = value.ToString(); int prefixLength; if (!int.TryParse(parameter.ToString(), out prefixLength) || s