WPF - C# Desktop App - DateGrid - IValueConverter

Markus Freitag 3,786 Reputation points
2020-07-26T15:36:32.44+00:00

Hello,

The converter is pretty powerful and I can do a lot with it. Perhaps this mechanism is an advantage over WinForms.

When and why do I need this line?
That would be the question of this thread. [ValueConversion(typeof(string), typeof(SolidColorBrush))]

  **[ValueConversion(typeof(string), typeof(SolidColorBrush))]**
    public class MagazineStateConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if ((value == null || ((string)value).Contains("0")))
                return Brushes.Red;
            else if ((value == null || ((string)value).ToLower().Contains("empty") || ((string)value).ToLower().Contains("leer")))
                return Brushes.Yellow;
            else
                return Brushes.Green;
        }


 public class ColorConverter : IValueConverter
   {
     public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
     {
       if (value.GetType() != typeof(ModeState)) return Brushes.Transparent;
       switch ((ModeState)value)
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,686 questions
{count} votes