using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ConditionalFormatting
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            _flex.ItemsSource = Product.GetProducts(200);
        }
    }

    public class ForegroundConverter : System.Windows.Data.IValueConverter
    {
        static SolidColorBrush _brBlack = new SolidColorBrush(Colors.Black);
        static SolidColorBrush _brRed = new SolidColorBrush(Colors.Red);
        static SolidColorBrush _brGreen = new SolidColorBrush(Colors.Green);

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var range = (Point)parameter;
            double val = (double)value;
            return
                val < range.X ? _brRed :
                val > range.Y ? _brGreen :
                _brBlack;
        }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class FontWeightConverter : System.Windows.Data.IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var range = (Point)parameter;
            double val = (double)value;
            return
                val < range.X ? FontWeights.Bold :
                val > range.Y ? FontWeights.Bold :
                FontWeights.Normal;
        }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
