forked from DevChatter/InteractiveSeven
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request DevChatter#77 from DevChatter/benrick/ui-updates
More UI updates
- Loading branch information
Showing
8 changed files
with
341 additions
and
140 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
44 changes: 44 additions & 0 deletions
44
src/InteractiveSeven/Behaviors/SelectAllTextOnFocusBehavior.cs
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,44 @@ | ||
using Microsoft.Xaml.Behaviors; | ||
using System.Windows.Controls; | ||
using System.Windows.Input; | ||
|
||
namespace InteractiveSeven.Behaviors | ||
{ | ||
public class SelectAllTextOnFocusBehavior : Behavior<TextBox> | ||
{ | ||
protected override void OnAttached() | ||
{ | ||
base.OnAttached(); | ||
AssociatedObject.GotKeyboardFocus += AssociatedObjectGotKeyboardFocus; | ||
AssociatedObject.GotMouseCapture += AssociatedObjectGotMouseCapture; | ||
AssociatedObject.PreviewMouseLeftButtonDown += AssociatedObjectPreviewMouseLeftButtonDown; | ||
} | ||
|
||
protected override void OnDetaching() | ||
{ | ||
base.OnDetaching(); | ||
AssociatedObject.GotKeyboardFocus -= AssociatedObjectGotKeyboardFocus; | ||
AssociatedObject.GotMouseCapture -= AssociatedObjectGotMouseCapture; | ||
AssociatedObject.PreviewMouseLeftButtonDown -= AssociatedObjectPreviewMouseLeftButtonDown; | ||
} | ||
|
||
private void AssociatedObjectGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) | ||
{ | ||
AssociatedObject.SelectAll(); | ||
} | ||
|
||
private void AssociatedObjectGotMouseCapture(object sender, MouseEventArgs e) | ||
{ | ||
AssociatedObject.SelectAll(); | ||
} | ||
|
||
private void AssociatedObjectPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) | ||
{ | ||
if (!AssociatedObject.IsKeyboardFocusWithin) | ||
{ | ||
AssociatedObject.Focus(); | ||
e.Handled = true; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.