using C1.Xaml;
using C1.Xaml.Chart;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;

namespace ControlExplorer.Controls.Chart
{
    public partial class Selection : UserControl//, IExposeApplicationBarItems
    {
        Random rnd = new Random();
        //AppBarButton btnColumn = new AppBarButton { Icon = new BitmapIcon { UriSource = new Uri("Resources/AppBar/chart_column.png", UriKind.Relative) } };
        //AppBarButton btnLine = new AppBarButton{ Icon = new BitmapIcon { UriSource =new Uri("Resources/AppBar/chart_line.png", UriKind.Relative)} };
        //AppBarButton btnPie = new AppBarButton { Icon = new BitmapIcon { UriSource = new Uri("Resources/AppBar/chart_pie.png", UriKind.Relative) } };

        public Selection()
        {
            InitializeComponent();

            //btnColumn.Label = "Column";
            //btnColumn.Tapped += btnColumn_Click;

            //btnLine.Label = "Line";
            //btnLine.Tapped += btnLine_Click;

            //btnPie.Label = "Pie";
            //btnPie.Tapped += btnPie_Click;

            // create sample data
            List<Product> products = new List<Product>();
            
            for (int i = 0; i < 5; i++)
                products.Add(new Product() { Name = "Product " + i, Price = rnd.Next(5, 50) });

            CollectionViewSource cvs = new CollectionViewSource();
            cvs.Source = products;

            c1Chart1.BeginUpdate();
            // set data source

            c1Chart1.Data.ItemsSource = cvs.View;
            c1Chart1.EndUpdate();

            flexGrid.ItemsSource = cvs.View;
        }

        //void btnColumn_Click(object sender, TappedRoutedEventArgs e)
        //{
        //    chart.ChartType = ChartType.Column;
        //    btnColumn.IsEnabled = false;
        //    btnPie.IsEnabled = true;
        //    btnLine.IsEnabled = true;
        //}

        //void btnLine_Click(object sender, TappedRoutedEventArgs e)
        //{
        //    chart.ChartType = ChartType.LineSymbols;
        //    btnColumn.IsEnabled = true;
        //    btnPie.IsEnabled = true;
        //    btnLine.IsEnabled = false;
        //}

        //void btnPie_Click(object sender, TappedRoutedEventArgs e)
        //{
        //    chart.ChartType = ChartType.Pie;
        //    btnColumn.IsEnabled = true;
        //    btnPie.IsEnabled = false;
        //    btnLine.IsEnabled = true;
        //}

        //#region IExposeApplicationBarItems Members

        //public IEnumerable<AppBarButton> ApplicationBarItems
        //{
        //    get
        //    {
        //        yield return btnColumn;
        //        yield return btnLine;
        //        yield return btnPie;
        //    }
        //}

        //#endregion

    }

    public class Product
    {
        public string Name { get; set; }
        public double Price { get; set; }
    }

//public class CollectionView<T> : ObservableCollection<T>, ICollectionView
//{
//    int currentPosition = -1;
//    object currentItem = null;

//    public bool CanFilter
//    {
//        get { throw new NotImplementedException(); }
//    }

//    public bool CanGroup
//    {
//        get { throw new NotImplementedException(); }
//    }

//    public bool CanSort
//    {
//        get { throw new NotImplementedException(); }
//    }

//    public bool Contains(object item)
//    {
//        throw new NotImplementedException();
//    }

//    public System.Globalization.CultureInfo Culture
//    {
//        get
//        {
//            throw new NotImplementedException();
//        }
//        set
//        {
//            throw new NotImplementedException();
//        }
//    }

//    public event EventHandler CurrentChanged;

//    public event CurrentChangingEventHandler CurrentChanging;

//    public object CurrentItem
//    {
//        get { return currentItem; }
//    }

//    public int CurrentPosition
//    {
//        get { return currentPosition; }
//    }

//    public IDisposable DeferRefresh()
//    {
//        throw new NotImplementedException();
//    }

//    public Predicate<object> Filter
//    {
//        get
//        {
//            throw new NotImplementedException();
//        }
//        set
//        {
//            throw new NotImplementedException();
//        }
//    }

//    public ObservableCollection<GroupDescription> GroupDescriptions
//    {
//        get { throw new NotImplementedException(); }
//    }

//    public ReadOnlyObservableCollection<object> Groups
//    {
//        get { throw new NotImplementedException(); }
//    }

//    public bool IsCurrentAfterLast
//    {
//        get { throw new NotImplementedException(); }
//    }

//    public bool IsCurrentBeforeFirst
//    {
//        get { throw new NotImplementedException(); }
//    }

//    public bool IsEmpty
//    {
//        get { return Count == 0; }
//    }

//    public bool MoveCurrentTo(object item)
//    {
//        if (item != null && item is T)
//        {
//            var index = IndexOf((T)item);
//            MoveCurrentToPosition(index);
//            return true;
//        }
//        return false;
//    }

//    public bool MoveCurrentToFirst()
//    {
//        return MoveCurrentToPosition(0);
//    }

//    public bool MoveCurrentToLast()
//    {
//        return MoveCurrentToPosition(Count - 1);
//    }

//    public bool MoveCurrentToNext()
//    {
//        throw new NotImplementedException();
//    }

//    public bool MoveCurrentToPosition(int position)
//    {
//        if (position >= 0 && position < Count)
//        {
//            if (CurrentChanging != null)
//                CurrentChanging(this, new CurrentChangingEventArgs());

//            currentPosition = position;
//            currentItem = this[position];

//            if (CurrentChanged != null)
//                CurrentChanged(this, EventArgs.Empty);
//            return true;
//        }

//        return false;
//    }

//    public bool MoveCurrentToPrevious()
//    {
//        throw new NotImplementedException();
//    }

//    public void Refresh()
//    {
//        throw new NotImplementedException();
//    }

//    public SortDescriptionCollection SortDescriptions
//    {
//        get { throw new NotImplementedException(); }
//    }

//    public System.Collections.IEnumerable SourceCollection
//    {
//        get { throw new NotImplementedException(); }
//    }
//}
}
