This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathTextBoxAutoCompleteTextInput.cs
More file actions
121 lines (102 loc) · 3.37 KB
/
Copy pathTextBoxAutoCompleteTextInput.cs
File metadata and controls
121 lines (102 loc) · 3.37 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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.ComponentModel;
using System.Reactive;
using System.Reactive.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Markup;
using ReactiveUI.Wpf;
using ReactiveUI;
namespace GitHub.UI
{
[ContentProperty("TextBox")]
public class TextBoxAutoCompleteTextInput : IAutoCompleteTextInput
{
TextBox textBox;
public event PropertyChangedEventHandler PropertyChanged;
public void Select(int position, int length)
{
textBox.Select(position, length);
}
public void SelectAll()
{
textBox.SelectAll();
}
public int CaretIndex
{
get { return textBox.CaretIndex; }
set { textBox.CaretIndex = value; }
}
public int SelectionStart
{
get { return textBox.SelectionStart; }
set { textBox.SelectionStart = value; }
}
public int SelectionLength
{
get { return textBox.SelectionLength; }
}
public string Text
{
get { return textBox.Text; }
set { textBox.Text = value; }
}
public IObservable<EventPattern<KeyEventArgs>> PreviewKeyDown
{
get;
private set;
}
public IObservable<EventPattern<RoutedEventArgs>> SelectionChanged { get; private set; }
public IObservable<EventPattern<TextChangedEventArgs>> TextChanged { get; private set; }
public UIElement Control { get { return textBox; } }
public Point GetPositionFromCharIndex(int charIndex)
{
var position = textBox.GetRectFromCharacterIndex(charIndex).BottomLeft;
position.Offset(0, 10); // Vertically pad it. Yeah, Point is mutable. WTF?
return position;
}
public void Focus()
{
Keyboard.Focus(textBox);
}
public TextBox TextBox
{
get
{
return textBox;
}
set
{
if (value != textBox)
{
textBox = value;
PreviewKeyDown = Observable.FromEventPattern<KeyEventHandler, KeyEventArgs>(
h => textBox.PreviewKeyDown += h,
h => textBox.PreviewKeyDown -= h);
SelectionChanged = Observable.FromEventPattern<RoutedEventHandler, RoutedEventArgs>(
h => textBox.SelectionChanged += h,
h => textBox.SelectionChanged -= h);
TextChanged = Observable.FromEventPattern<TextChangedEventHandler, TextChangedEventArgs>(
h => textBox.TextChanged += h,
h => textBox.TextChanged -= h);
NotifyPropertyChanged("Control");
}
}
}
public Thickness Margin
{
get { return textBox.Margin; }
set { textBox.Margin = value; }
}
private void NotifyPropertyChanged(String info)
{
var propertyChanged = PropertyChanged;
if (propertyChanged != null)
{
propertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
}