Language: C#
UpdateSourceTrigger PropertyChanged Silverlight Behavior
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(); } } }
Report Abuse
Subscribe
Discuss
News
About
New Snippet
Recent Snippets
My Snippets
Favorites
Web Code
Search
Copy
Line#