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;
using System.Diagnostics;

namespace AnimatedCellsOnValueChange
{
    public partial class StockPricePresenter : UserControl
    {
        public StockPricePresenter()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(StockPricePresenter_Loaded);
        }

        void StockPricePresenter_Loaded(object sender, RoutedEventArgs e)
        {
            this.textBlock.Text = string.Format("{0:c}",this.StockPrice);
            
            if (this.StockPrice < this.OldStockPrice)
            {
                 ((Storyboard)((StockPricePresenter)sender).Resources["RedToTransparent"]).Begin();
                 this.Arrow.Fill = new SolidColorBrush(Colors.Red);
                 this.ArrowTransform.Angle = 90;
            }
            else
            {
                ((Storyboard)((StockPricePresenter)sender).Resources["GreenToTransparent"]).Begin();
                this.Arrow.Fill = new SolidColorBrush(Colors.Green);
                this.ArrowTransform.Angle = -90;
            }
        }


        public decimal StockPrice
        {
            get { return (decimal)GetValue(StockPriceProperty); }
            set { SetValue(StockPriceProperty, value); }
        }

        // Using a DependencyProperty as the backing store for StockPrice.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty StockPriceProperty =
            DependencyProperty.Register("StockPrice", typeof(decimal), typeof(StockPricePresenter), new PropertyMetadata(null));

        public decimal OldStockPrice
        {
            get { return (decimal)GetValue(OldStockPriceProperty); }
            set { SetValue(OldStockPriceProperty, value); }
        }

        // Using a DependencyProperty as the backing store for OldStockPrice.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty OldStockPriceProperty =   
            DependencyProperty.Register("OldStockPrice", typeof(decimal), typeof(StockPricePresenter), new PropertyMetadata(null));
    }
}
