using System;
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 C1.Silverlight.Extended;
using System.ComponentModel;
using System.IO;

namespace C1Extended_Demo
{
    public partial class CustomEditors : UserControl
    {
        public CustomEditors()
        {
            InitializeComponent();

            _customPropertyGrid.AvailableEditors.Insert(0, new SpectrumColorEditor());
            _customPropertyGrid.AvailableEditors.Insert(0, new SliderNumericEditor());
            _customPropertyGrid.AvailableEditors.Insert(0, new DateTimeEditor());
            _customPropertyGrid.AvailableEditors.Insert(0, new FileEditor());
            var source = new Item();
            _propertyGrid.SelectedObject = source;
            _customPropertyGrid.SelectedObject = source;
            _customPropertyGrid.PropertyAttributes.Add(new PropertyAttribute()
            {
                MemberName = "Color1",
                Editor = new HexColorEditor()
            });

            _customPropertyGrid.PropertyAttributes.Add(new PropertyAttribute()
            {
                MemberName = "Double1",
                MinimumValue = 0,
                MaximumValue = 100
            });
        }

        private void _customPropertyGrid_PropertyBoxAdded(object sender, PropertyBoxChangedEventArgs e)
        {
            if (e.PropertyBox.PropertyAttribute.MemberName == "Double1")
            {
                e.PropertyBox.PropertyAttribute.MinimumValue = 0;
                e.PropertyBox.PropertyAttribute.MaximumValue = 100;
            }
        }
    }

    public class Item : INotifyPropertyChanged
    {
        private Color _color1;
        private Color _color2;
        private decimal? _double1;
        private DateTime _dateTime1;
        private FileInfo _file1;

        public Color Color1
        {
            get
            {
                return _color1;
            }
            set
            {
                _color1 = value;
                if(PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("Color1"));
            }
        }

        public Color Color2
        {
            get
            {
                return _color2;
            }
            set
            {
                _color2 = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("Color2"));
            }
        }

        public decimal? Double1
        {
            get { return _double1; }
            set { 
                _double1 = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("Double1"));
            }
        }

        public DateTime DateTime1
        {
            get { return _dateTime1; }
            set
            {
                _dateTime1 = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("DateTime1"));
            }
        }

        public FileInfo File1
        {
            get { return _file1; }
            set
            {
                _file1 = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("File1"));
            }
        }
        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}
