using System;
using System.Net;
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 C1.Silverlight;
using C1.Silverlight.Extended;
using System.Windows.Data;

namespace C1Extended_Demo
{
    public class MaskedEditor : C1MaskedTextBox, ITypeEditorControl
    {

        #region ITypeEditorControl Members

        public bool Supports(PropertyAttribute Property)
        {
            return Property.PropertyInfo.PropertyType == typeof(string);
        }

        public ITypeEditorControl Create()
        {
            return new MaskedEditor() { Mask = Mask };
        }

        public void Attach(PropertyAttribute property)
        {
            var binding = new Binding(property.PropertyInfo.Name)
            {
                Mode = BindingMode.TwoWay,
                Source = property.SelectedObject,
                ValidatesOnExceptions = true
            };
            this.TextMaskFormat = MaskFormat.IncludePromptAndLiterals;
            this.SetBinding(C1MaskedTextBox.ValueProperty, binding);
        }

        public void Detach(PropertyAttribute property)
        {
        }

        public event System.ComponentModel.PropertyChangedEventHandler ValueChanged;

        #endregion

    }
}
