Cannot see _ (underscore) in WPF content

后端 未结 5 1047
挽巷
挽巷 2020-12-03 20:34

A very simple question:

Why I cant see _ (underscore) in WPF content?

For instance the content of

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 21:17

    I was binding to a data source which I didn't want to change, so I used a custom converter to create the missing underscore:

    [ValueConversion(typeof(string), typeof(string))]
    public class ShowUnderscoreConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
            value is string text ? text.Replace("_", "__") : null;
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => 
            value is string text ? text.Replace("__", "_") : null;
    }
    

提交回复
热议问题