2020-08-26 14:27:10 +08:00
|
|
|
|
using System.Windows.Controls;
|
2017-12-09 22:11:03 +08:00
|
|
|
|
using System.Windows.Input;
|
2020-08-26 14:27:10 +08:00
|
|
|
|
using Microsoft.Xaml.Behaviors;
|
2017-12-09 22:11:03 +08:00
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|