using System;
using System.Windows.Controls;
using System.Windows;
namespace Microsoft.Windows.Controls.Primitives
{
public abstract class InputBase : Control
{
#region Members
///
/// Flags if the Text and Value properties are in the process of being sync'd
///
private bool _isSyncingTextAndValueProperties;
private bool _isInitialized;
#endregion //Members
#region Properties
public virtual object PreviousValue { get; internal set; }
#region IsEditable
public static readonly DependencyProperty IsEditableProperty = DependencyProperty.Register("IsEditable", typeof(bool), typeof(InputBase), new PropertyMetadata(true));
public bool IsEditable
{
get { return (bool)GetValue(IsEditableProperty); }
set { SetValue(IsEditableProperty, value); }
}
#endregion //IsEditable
#region Text
public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(InputBase), new FrameworkPropertyMetadata(default(String), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnTextPropertyChanged));
public string Text
{
get { return (string)this.GetValue(TextProperty); }
set { this.SetValue(TextProperty, value); }
}
private static void OnTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
InputBase input = (InputBase)d;
input.OnTextChanged((string)e.OldValue, (string)e.NewValue);
if (input._isInitialized)
input.SyncTextAndValueProperties(e.Property, e.NewValue);
}
protected virtual void OnTextChanged(string previousValue, string currentValue)
{
}
#endregion //Text
#region Value
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(object), typeof(InputBase), new FrameworkPropertyMetadata(default(object), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnValuePropertyChanged, OnCoerceValuePropertyCallback));
public virtual object Value
{
get { return (object)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
private static void OnValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
InputBase input = (InputBase)d;
if (e.OldValue != e.NewValue)
{
input.PreviousValue = e.OldValue;
input.OnValueChanged(e.OldValue, e.NewValue);
if (input._isInitialized)
input.SyncTextAndValueProperties(e.Property, e.NewValue);
}
}
protected virtual void OnValueChanged(object oldValue, object newValue)
{
RoutedPropertyChangedEventArgs