using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Data;
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 Telerik.Windows.Controls;
using Telerik.Windows.Rendering;

namespace Telerik.Windows.Examples.GanttView.FirstLook
    {
    public partial class Example : UserControl
        {
        public Example()
            {
            InitializeComponent();

            this.ganttview.Loaded += OnGanttViewLoaded;

            //this.Loaded += this.OnLoaded;
            //this.Unloaded += this.UnLoaded;
            }

        //private void OnLoaded(object sender, RoutedEventArgs e)
        //    {
        //    ApplicationThemeManager.GetInstance().ThemeChanged += this.Example_ThemeChanged;
        //    }

        //private void UnLoaded(object sender, RoutedEventArgs e)
        //    {
        //    ApplicationThemeManager.GetInstance().ThemeChanged -= this.Example_ThemeChanged;
        //    }

        void OnGanttViewLoaded(object sender, RoutedEventArgs e)
            {
            var panels = this.ganttview.ChildrenOfType<LogicalCanvasPanel>().ToList();

            double visibleArea = panels.Where(p => p.Name == "EventsPanel").First().ViewportWidth;

            var viewModel = this.ganttview.DataContext as ViewModel;

            viewModel.VisibleArea = (long)visibleArea;
            }
        }

    public class Converter : IValueConverter
        {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
            var date = value.ToString();

            var parts = date.Split(new char[] { ' ' });
            return parts[0];
            }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
            return value;
            }
        }
    }
