CefSharp.MinimalExample/CefSharp.MinimalExample.Wpf/Behaviours/TextBoxBindingUpdateOnEnterBehaviour.cs
amaitland 337b617b46 WPF - Use Microsoft.Xaml.Behaviors.Wpf
Migrate from System.Windows.Interactivity.WPF to Microsoft.Xaml.Behaviors.Wpf
2020-09-09 17:53:53 +10:00

29 lines
766 B
C#

using System.Windows.Controls;
using System.Windows.Input;
using Microsoft.Xaml.Behaviors;
namespace CefSharp.MinimalExample.Wpf.Behaviours
{
public class TextBoxBindingUpdateOnEnterBehaviour : Behavior<TextBox>
{
protected override void OnAttached()
{
AssociatedObject.KeyDown += OnTextBoxKeyDown;
}
protected override void OnDetaching()
{
AssociatedObject.KeyDown -= OnTextBoxKeyDown;
}
private void OnTextBoxKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
var txtBox = sender as TextBox;
txtBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
}
}
}
}