using System.Windows.Controls;
using System.Windows.Interactivity;

namespace Silverlight_LearningToUseBehaviors.Behaviors
{
    public class ImmediateUpdateBehavior : Behavior<TextBox>
    {
        protected override void OnAttached()
        {
            base.OnAttached();
            AssociatedObject.TextChanged += OnTextChanged;
        }

        protected override void OnDetaching()
        {
            base.OnDetaching();
            AssociatedObject.TextChanged -= OnTextChanged;
        }


        void OnTextChanged(object sender, TextChangedEventArgs e)
        {
            AssociatedObject.GetBindingExpression(TextBox.TextProperty).UpdateSource();
        }
    }
}