-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update IP address on both PropertyChanged and LostFocus
- Loading branch information
Showing
2 changed files
with
36 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using Microsoft.Xaml.Behaviors; | ||
|
||
namespace fs2ff.Behaviors | ||
{ | ||
public class UpdateSourceOnLostFocusBehavior : Behavior<TextBox> | ||
{ | ||
protected override void OnAttached() | ||
{ | ||
base.OnAttached(); | ||
|
||
if (AssociatedObject != null) | ||
AssociatedObject.LostFocus += AssociatedObject_LostFocus; | ||
} | ||
|
||
protected override void OnDetaching() | ||
{ | ||
if (AssociatedObject != null) | ||
AssociatedObject.LostFocus -= AssociatedObject_LostFocus; | ||
|
||
base.OnDetaching(); | ||
} | ||
|
||
private static void AssociatedObject_LostFocus(object sender, RoutedEventArgs e) | ||
{ | ||
if (sender is TextBox textBox) | ||
BindingOperations.GetBindingExpression(textBox, TextBox.TextProperty)?.UpdateSource(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters