client/src/Iri.Modernisation.Controls/View/HeaderProduction/HeaderProductionPartControler.xaml.cs
author totetm <>
Fri, 12 Feb 2010 16:22:57 +0100
changeset 47 9b26023b8c83
parent 38 bd33267300aa
permissions -rw-r--r--
Fixed| bug si on ferme un livre en le lisant ReFixed|faire fonctionner le seek, même quand play n'est pas activer

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
namespace Iri.Modernisation.Controls.View
{
	public partial class HeaderProductionPartControler : UserControl
	{

		public bool HighLighted
        {
            get { return (bool)GetValue(HighLightProperty); }
            set { 
                
                SetValue(HighLightProperty, value); 
            }
        }

        // Using a DependencyProperty as the backing store for HighLight.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty HighLightProperty =
            DependencyProperty.Register("HighLighted", typeof(bool), typeof(HeaderProductionPartControler), new PropertyMetadata(new PropertyChangedCallback(HighLightChange)));
        private static void HighLightChange(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {

            if((bool)e.NewValue)
            {
                ((HeaderProductionPartControler)sender).Select();
            }
            else
            {
                ((HeaderProductionPartControler)sender).UnSelect();
            }
        }
        public bool Active
        {
            get { return (bool)GetValue(ActiveProperty); }
            set 
            { 
                
               
                SetValue(ActiveProperty, value);
                if (value)
                {
                    Activate();
                    if (HighLighted)
                    {
                        Select();
                    }
                }
                else
                {
                }
            }
        }

        // Using a DependencyProperty as the backing store for IsActive.  This enables animation, styling, binding, etc...
        public  static readonly DependencyProperty ActiveProperty =
            DependencyProperty.Register("Active", typeof(bool), typeof(HeaderProductionPartControler), new PropertyMetadata(new PropertyChangedCallback(ItemsSourceChanged)));
        private static void ItemsSourceChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {

            ((HeaderProductionPartControler)sender).Active =(bool)e.NewValue;
        }




        public String Text
        {
            get { return (String)GetValue(TextProperty); }
            set 
            { SetValue(TextProperty, value); 
                textBlock.Text = value; 
            }
        }
            
        // Using a DependencyProperty as the backing store for Text.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TextProperty =
            DependencyProperty.Register("Text", typeof(String), typeof(HeaderProductionPartControler), new PropertyMetadata(""));


		
		public HeaderProductionPartControler()
		{
			// Required to initialize variables
			InitializeComponent();
           
			_activated = false;
			_finished= false;
          
            
           

		}
		
        private bool _activated;
		private bool _finished;
		
		public void Activate()
		{
			if(!_activated && !_finished)
			{
				VisualStateManager.GoToState(this,"Available",true);
				_activated=true;
			}
            
		}
		
		public void UnSelect()
		{
            if (_activated && !_finished)
            {
                VisualStateManager.GoToState(this, "Available", true);
            }
		}
		private void Button_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
		{
           
		
		}

		private void but_Click(object sender, System.Windows.RoutedEventArgs e)
		{
		     	
				if(_activated)
				{
                    Clicked(this, new EventArgs());

                      
				}
		}
        public void Finish()
        {
            VisualStateManager.GoToState(this,"Finished",true);
                           if (HeaderProductionPartFinished!=null)
                           {
                             HeaderProductionPartFinished(this, new HeaderProductionPartControlerEventArgs(this));
                           }
                           _finished = true;
        }
        public event EventHandler Clicked;
        public void Select()
        {
            if (_activated && !_finished)
            {
                VisualStateManager.GoToState(this, "Selected", true);
            }
        }
		private void textBlock_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
		{
            if (_activated && !_finished)
            {
                if (HeaderProductionPartSelected != null)
                    HeaderProductionPartSelected(this, new HeaderProductionPartControlerEventArgs(this));
            }
        }
        public event EventHandler<HeaderProductionPartControlerEventArgs> HeaderProductionPartFinished;
        public event EventHandler<HeaderProductionPartControlerEventArgs> HeaderProductionPartSelected;
	}

    public class HeaderProductionPartControlerEventArgs : EventArgs
    {
        public object sender { get; set; }
        public HeaderProductionPartControlerEventArgs(object psender)
        {
            sender = psender;
        }

    }
}