using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace WpfApplication2
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        AnalyzeHelper mHelper;
        public MainWindow()
        {
            InitializeComponent();
        }
        public void Init(AnalyzeHelper helper) 
        {
            mHelper = helper;
            this.DataContext = mHelper;
        }
    }
    public class AnalyzeHelper:INotifyPropertyChanged
    {
        private double avg = 0;
        public double Avg 
        {
            get {
                return avg;
            }
            set {
                if (avg != value)
                {
                    avg = value;
                    NotifyPropertyChanged("Avg");
                }
            }
        }

        public void Init(double[] thicks, TimeSpan interval, double velocity) 
        {
            if(thicks.Length>0)
                Avg = thicks.Average();
        }
        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged(string propertyname)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyname));
            }
        }
        #endregion
    }
}