Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
265
Use FormatString in Code Behind
posted

I know I can apply FormatString to format Column Display in XAML. But I want to format Columns dynamically (depending on some conditions). How can I implement it in Code Behind? Thanks.

Parents
  • 2690
    posted

    You can use valueConverter

     

    It would look like

     public class DecimalEditorValueConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                return String.Format(culture, "{0:N2}", value);
            }

            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                return value;
            }
        }

     

    and in xaml use it with your control as

      ValueConverter="{StaticResource DecimalEditorValueConverter }"

Reply Children