You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.1 KiB

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
namespace BindingValidationRuleSample.Converter
{
[ValueConversion(typeof(int), typeof(Brush))]
internal class ButtonTextBrush : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (targetType != typeof(Brush))
return null;
if (value == null)
return null;
int age = int.Parse(value.ToString());
return ValueColor(age);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
private Brush ValueColor(int age)
{
if (age >= 10 && age < 20)
return Brushes.HotPink;
if (age >= 20 && age < 30)
return Brushes.DarkOliveGreen;
return Brushes.MediumPurple;
}
}
}