using System;
using System.Windows;
using Telerik.Windows.Controls.ChartView;
using WpfApplication1.Models;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            this.SetUpGenericDataBinding();
        }
  
        private void SetUpGenericDataBinding()
        {
            var categoryBinding = new GenericDataPointBinding<DowJonesData, DateTime>() { ValueSelector = c => c.Date };
            (this.chart.Series[0] as LineSeries).CategoryBinding = categoryBinding;
            (this.chart.Series[0] as LineSeries).ValueBinding = new GenericDataPointBinding<DowJonesData, double>() { ValueSelector = c => c.Open };
            (this.chart.Series[1] as LineSeries).CategoryBinding = categoryBinding;
            (this.chart.Series[1] as LineSeries).ValueBinding = new GenericDataPointBinding<DowJonesData, double>() { ValueSelector = c => c.High };
            (this.chart.Series[2] as LineSeries).CategoryBinding = categoryBinding;
            (this.chart.Series[2] as LineSeries).ValueBinding = new GenericDataPointBinding<DowJonesData, double>() { ValueSelector = c => c.Low };
            (this.chart.Series[3] as LineSeries).CategoryBinding = categoryBinding;
            (this.chart.Series[3] as LineSeries).ValueBinding = new GenericDataPointBinding<DowJonesData, double>() { ValueSelector = c => c.Close };
        }

        private void SetUpPropertyDataBinding()
        {
            var categoryBinding = new PropertyNameDataPointBinding("Date");
            (this.chart.Series[0] as LineSeries).CategoryBinding = categoryBinding;
            (this.chart.Series[0] as LineSeries).ValueBinding = new PropertyNameDataPointBinding("Open");
            (this.chart.Series[1] as LineSeries).CategoryBinding = categoryBinding;
            (this.chart.Series[1] as LineSeries).ValueBinding = new PropertyNameDataPointBinding("High");
            (this.chart.Series[2] as LineSeries).CategoryBinding = categoryBinding;
            (this.chart.Series[2] as LineSeries).ValueBinding = new PropertyNameDataPointBinding("Low");
            (this.chart.Series[3] as LineSeries).CategoryBinding = categoryBinding;
            (this.chart.Series[3] as LineSeries).ValueBinding = new PropertyNameDataPointBinding("Close");
        }
    }
}
