client/src/Iri.Modernisation.Controls/View/BookTimeLine/BookTimeLine.xaml.cs
author Matthieu Totet
Mon, 23 Nov 2009 10:17:33 +0100
changeset 7 de7ba61f66c7
parent 0 249d70e7b32d
child 18 66911d0f0eb6
permissions -rw-r--r--
Add element to personal chutier

using System;
using System.Windows.Data;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
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 Iri.Modernisation.Data.Models;
using Iri.Modernisation.Controls.ViewModel;
using Iri.Modernisation.BaseMVVM.Commands;
namespace Iri.Modernisation.Controls.View
{
    public partial class BookTimeLine : UserControl
    {
        public BookTimeLine()
        {
            InitializeComponent();
       
            TimeStripsPanel.SizeChanged += new SizeChangedEventHandler(TimeStripsPanel_SizeChanged);
            BookTimeLineSlider.MouseLeftButtonUp += Commands.TimeChange.Execute;
        }
		
        void TimeStripsPanel_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            Draw();
        }

       
        public void Draw()
        {
            BookTimeLineVM VM = (BookTimeLineVM)DataContext;
            BookTimeLineElementPanel.Children.Clear();
            foreach (List<SegmentIndex> LIndex in VM.SegmentIndex)
            {
                foreach (SegmentIndex Index in LIndex)
                {
                   
                    PolemicElementControl pol = new PolemicElementControl();
                    
                    pol.SetValue(Canvas.ZIndexProperty, 10);
                    pol.DataContext = new PolemicElementVM(Index);
                    BookTimeLineElementPanel.Children.Add(pol);
                    Canvas.SetLeft(pol, (Index.TimerIn.TotalMilliseconds * ScaleTimeLine.Value) / VM.TotalDuration);
                    pol.Width = (Index.Duration.TotalMilliseconds * ScaleTimeLine.Value) / VM.TotalDuration;
                }
            }
            int basi = 30;
            foreach (List<Annotation> LAnnotation in VM.Annotations)
            {
                foreach (Annotation Annotation in LAnnotation)
                {
                    PolemicElementControl pol = new PolemicElementControl();
                    pol.SetValue(Canvas.ZIndexProperty, 10);
                    pol.DataContext = new PolemicElementVM(Annotation);
                    BookTimeLineElementPanel.Children.Add(pol);
                    Canvas.SetLeft(pol, (Annotation.TimerIn.TotalMilliseconds * ScaleTimeLine.Value) / VM.TotalDuration);
                    Canvas.SetTop(pol, basi);
                    basi += 10;
                    pol.Width = (Annotation.Duration.TotalMilliseconds * ScaleTimeLine.Value) / VM.TotalDuration;
                }
            }
            BookTimeLineElementPanel.UpdateLayout();
        }

        private void BookTimeLineSlider_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            MessageBox.Show("Change");
            BookTimeLineSlider.Value = (e.GetPosition(BookTimeLineSlider).X) * BookTimeLineSlider.Maximum / BookTimeLineSlider.Width;
        }

        
        
        
       
    }

}