-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
52 lines (48 loc) · 1.54 KB
/
App.xaml.cs
File metadata and controls
52 lines (48 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace Imperial_Commander_Editor
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override void OnStartup( StartupEventArgs e )
{
// Select the text in a TextBox when it receives focus
EventManager.RegisterClassHandler( typeof( TextBox ), TextBox.PreviewMouseLeftButtonDownEvent,
new MouseButtonEventHandler( SelectivelyIgnoreMouseButton ) );
EventManager.RegisterClassHandler( typeof( TextBox ), TextBox.GotKeyboardFocusEvent,
new RoutedEventHandler( SelectAllText ) );
EventManager.RegisterClassHandler( typeof( TextBox ), TextBox.MouseDoubleClickEvent,
new RoutedEventHandler( SelectAllText ) );
base.OnStartup( e );
}
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 focused, give it the focus and
// stop further processing of this click event
textBox.Focus();
e.Handled = true;
}
}
}
void SelectAllText( object sender, RoutedEventArgs e )
{
var textBox = e.OriginalSource as TextBox;
if ( textBox != null )
textBox.SelectAll();
}
}
}