init
This commit is contained in:
36
Common/DTS.CommonCore/Behaviors/TrimTextBoxBehavior.cs
Normal file
36
Common/DTS.CommonCore/Behaviors/TrimTextBoxBehavior.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Interactivity;
|
||||
|
||||
namespace DTS.Common.Behaviors
|
||||
{
|
||||
|
||||
public class TrimTextBoxBehavior : Behavior<TextBox>
|
||||
{
|
||||
protected override void OnAttached()
|
||||
{
|
||||
base.OnAttached();
|
||||
|
||||
AssociatedObject.LostFocus += AssociatedObject_LostFocus;
|
||||
|
||||
}
|
||||
|
||||
private void AssociatedObject_LostFocus(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var trim = AssociatedObject.Text.Trim();
|
||||
if (trim != AssociatedObject.Text)
|
||||
{
|
||||
AssociatedObject.Text = trim;
|
||||
AssociatedObject.GetBindingExpression(TextBox.TextProperty).UpdateSource();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDetaching()
|
||||
{
|
||||
base.OnDetaching();
|
||||
|
||||
AssociatedObject.LostFocus -= AssociatedObject_LostFocus;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user