blob: a66d18c5e1440361a8f85ff5e6ada6b3e4836d5f (
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
69
70
71
72
73
74
75
76
77
78
79
80
|
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Controls;
using System.Windows.Input;
namespace Xamarin.PropertyEditing.Windows
{
internal class ComboBoxEx
: ComboBox
{
static ComboBoxEx ()
{
DefaultStyleKeyProperty.OverrideMetadata (typeof (ComboBoxEx), new FrameworkPropertyMetadata (typeof (ComboBoxEx)));
}
public static readonly DependencyProperty EnableSubmitProperty = DependencyProperty.Register (
"EnableSubmit", typeof (bool), typeof (ComboBoxEx), new PropertyMetadata (true));
public bool EnableSubmit
{
get { return (bool)GetValue (EnableSubmitProperty); }
set { SetValue (EnableSubmitProperty, value); }
}
protected override AutomationPeer OnCreateAutomationPeer ()
{
return new ComboBoxExAutomationPeer (this);
}
protected override void OnSelectionChanged (SelectionChangedEventArgs e)
{
base.OnSelectionChanged (e);
Submit();
}
protected override void OnKeyDown (KeyEventArgs e)
{
if (e.Key == Key.Enter) {
Submit ();
e.Handled = true;
}
base.OnKeyDown (e);
}
protected override void OnLostKeyboardFocus (KeyboardFocusChangedEventArgs e)
{
base.OnLostKeyboardFocus (e);
Submit ();
}
protected virtual void OnSubmit ()
{
var expression = GetBindingExpression (TextProperty);
expression?.UpdateSource ();
}
private void Submit ()
{
if (!EnableSubmit)
return;
OnSubmit();
}
private class ComboBoxExAutomationPeer
: ComboBoxAutomationPeer
{
public ComboBoxExAutomationPeer (ComboBox owner)
: base (owner)
{
}
protected override bool IsControlElementCore ()
{
return base.IsControlElementCore () && Owner.IsVisible;
}
}
}
}
|