CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets My Favorites Favorites Web Code Search Snippets Search
Sign inor Register
Language: C#

UpdateSourceTrigger PropertyChanged Silverlight Behavior

830 Views   
using System;
using System.Windows.Controls;
using System.Windows.Interactivity;
 
namespace SLTextBoxBehaviorTest
{
    public class UpdateSourceTriggerPropertyChangedBehavior : Behavior<TextBox>
    {
        protected override void OnAttached()
        {
            base.OnAttached();
 
            this.AssociatedObject.TextChanged += TextChanged;
        }
 
        protected override void OnDetaching()
        {
            base.OnDetaching();
 
            this.AssociatedObject.TextChanged -= TextChanged;
        }
 
        protected void TextChanged(object sender, TextChangedEventArgs e)
        {
            var binding = this.AssociatedObject.GetBindingExpression(TextBox.TextProperty);
 
            if (binding == null)
                return;
 
            if (binding.ParentBinding.Mode != System.Windows.Data.BindingMode.TwoWay)
                return;
 
            binding.UpdateSource();
        }
    }
}
by Grumpydev
  June 09, 2010 @ 6:28am

Add a comment


Report Abuse
brought to you by:
West Wind Techologies