This repository has been archived by the owner on Aug 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #6 - Таймер закончился. Кликаешь по полю (чтобы курсор попал на ц…
…ифру) - сбрасывается выделение
- Loading branch information
Showing
3 changed files
with
59 additions
and
4 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,54 @@ | ||
namespace OrzeszekTimer | ||
{ | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
|
||
/// <summary> | ||
/// We have it so the first click selects all, and another click goes to cursor | ||
/// </summary> | ||
/// <remarks> | ||
/// http://stackoverflow.com/a/661224/136559 | ||
/// </remarks> | ||
public class ClickSelectTextBox : TextBox | ||
{ | ||
public ClickSelectTextBox() | ||
{ | ||
this.AddHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(SelectivelyIgnoreMouseButton), true); | ||
this.AddHandler(GotKeyboardFocusEvent, new RoutedEventHandler(SelectAllText), true); | ||
this.AddHandler(MouseDoubleClickEvent, new RoutedEventHandler(SelectAllText), true); | ||
} | ||
|
||
private static void SelectivelyIgnoreMouseButton(object sender, MouseButtonEventArgs e) | ||
{ | ||
// Find the TextBox | ||
DependencyObject parent = e.OriginalSource as UIElement; | ||
while (parent != null && !(parent is TextBox)) | ||
{ | ||
parent = VisualTreeHelper.GetParent(parent); | ||
} | ||
|
||
if (parent != null) | ||
{ | ||
var textBox = (TextBox)parent; | ||
if (!textBox.IsKeyboardFocusWithin) | ||
{ | ||
// If the text box is not yet focussed, give it the focus and | ||
// stop further processing of this click event. | ||
textBox.Focus(); | ||
e.Handled = true; | ||
} | ||
} | ||
} | ||
|
||
private static void SelectAllText(object sender, RoutedEventArgs e) | ||
{ | ||
var textBox = e.OriginalSource as TextBox; | ||
if (textBox != null) | ||
{ | ||
textBox.SelectAll(); | ||
} | ||
} | ||
} | ||
} |
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
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