using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Data; using DynamicStyling.Business_Classes; using System.Windows.Media; namespace DynamicStyling.Converters { //public class AgeToGradientStopColorConverter : IValueConverter //{ // #region IValueConverter Members // public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) // { // if (value is Person) // { // int temp = ((Person)value).Age; // // adding 0.2 to better observe the effect // return ((double)temp / 100) + 0.2; // } // else // return 0; // } // public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) // { // throw new NotImplementedException(); // } // #endregion //} public class AgeToGradientStopConverter : IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value is Person) { double temp = (double)((Person)value).Age/100; var linBrush = new LinearGradientBrush(); linBrush.StartPoint = new System.Windows.Point(0, 0); linBrush.EndPoint = new System.Windows.Point(1, 0); linBrush.GradientStops.Add(new GradientStop(Color.FromRgb(192, 255, 192), temp)); linBrush.GradientStops.Add(new GradientStop(Color.FromArgb(255, 255, 255, 255), temp + 0.001)); return linBrush; } else return Binding.DoNothing; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } #endregion } }