using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

using C1.Xaml.Chart;

namespace ChartSamples
{
    public sealed partial class Markers : UserControl
    {
        public Markers()
        {
            this.InitializeComponent();

            // can't set NaN in XAML so we must set in code
            ((ChartPanel)c1Chart2.View.Layers[0]).Children[0].DataPoint = new Point(-1, double.NaN);
            ((ChartPanel)c1Chart_Crosshairs.View.Layers[0]).Children[0].DataPoint = new Point(-1, double.NaN);
            ((ChartPanel)c1Chart_Crosshairs.View.Layers[0]).Children[1].DataPoint = new Point(double.NaN, -1);
 
        }

        private void chkSnap_Checked(object sender, RoutedEventArgs e)
        {
            if (c1Chart_Crosshairs != null)
            {
                ((ChartPanel)c1Chart_Crosshairs.View.Layers[0]).Children[0].Attach = ChartPanelAttach.DataXY;
                ((ChartPanel)c1Chart_Crosshairs.View.Layers[0]).Children[1].Attach = ChartPanelAttach.DataXY;
                ((ChartPanel)c1Chart_Crosshairs.View.Layers[0]).Children[2].Attach = ChartPanelAttach.DataXY;
            }
        }

        private void chkSnap_Unchecked(object sender, RoutedEventArgs e)
        {
            ((ChartPanel)c1Chart_Crosshairs.View.Layers[0]).Children[0].Attach = ChartPanelAttach.None;
            ((ChartPanel)c1Chart_Crosshairs.View.Layers[0]).Children[1].Attach = ChartPanelAttach.None;
            ((ChartPanel)c1Chart_Crosshairs.View.Layers[0]).Children[2].Attach = ChartPanelAttach.None;
        }

        private void dot_DataPointChanged(object sender, EventArgs e)
        {
            var cpobj = (ChartPanelObject)sender;
            if(cpobj.DataPoint.X > 1)
                txtLabel.Text = cpobj.DataPoint.X.FromOADate().AddDays(1).ToString("MMMM d") + " " + DateTime.Now.Year.ToString() +
                    ", (" + cpobj.DataPoint.Y.ToString() + ")";
        }
    }
}
