blob: 3801fe81ef348360dae0ab58b3987a8657f5275d (
plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
using System;
using System.Windows;
using System.Windows.Controls;
namespace MaterialDesignThemes.Wpf
{
public static partial class HintProxyFabric
{
private sealed class TextBoxHintProxy : IHintProxy
{
private readonly TextBox _textBox;
public object Content => _textBox.Text;
public bool IsLoaded => _textBox.IsLoaded;
public bool IsVisible => _textBox.IsVisible;
public bool IsEmpty() => string.IsNullOrEmpty(_textBox.Text);
public bool IsFocused() => _textBox.IsKeyboardFocused;
public event EventHandler ContentChanged;
public event EventHandler IsVisibleChanged;
public event EventHandler Loaded;
public event EventHandler FocusedChanged;
public TextBoxHintProxy(TextBox textBox)
{
if (textBox == null) throw new ArgumentNullException(nameof(textBox));
_textBox = textBox;
_textBox.TextChanged += TextBoxTextChanged;
_textBox.Loaded += TextBoxLoaded;
_textBox.IsVisibleChanged += TextBoxIsVisibleChanged;
_textBox.IsKeyboardFocusedChanged += TextBoxIsKeyboardFocusedChanged;
}
private void TextBoxIsKeyboardFocusedChanged(object sender, DependencyPropertyChangedEventArgs e)
{
FocusedChanged?.Invoke(sender, EventArgs.Empty);
}
private void TextBoxIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
IsVisibleChanged?.Invoke(sender, EventArgs.Empty);
}
private void TextBoxLoaded(object sender, RoutedEventArgs e)
{
Loaded?.Invoke(sender, EventArgs.Empty);
}
private void TextBoxTextChanged(object sender, TextChangedEventArgs e)
{
ContentChanged?.Invoke(sender, EventArgs.Empty);
}
public void Dispose()
{
_textBox.TextChanged -= TextBoxTextChanged;
_textBox.Loaded -= TextBoxLoaded;
_textBox.IsVisibleChanged -= TextBoxIsVisibleChanged;
_textBox.IsKeyboardFocusedChanged -= TextBoxIsKeyboardFocusedChanged;
}
}
}
}
|