aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Console/ConsoleTextBox.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Tango.Console/ConsoleTextBox.cs')
-rw-r--r--Software/Visual_Studio/Tango.Console/ConsoleTextBox.cs60
1 files changed, 60 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Console/ConsoleTextBox.cs b/Software/Visual_Studio/Tango.Console/ConsoleTextBox.cs
new file mode 100644
index 000000000..e2f1f53c3
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Console/ConsoleTextBox.cs
@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace Tango.Console
+{
+ public class ConsoleTextBox : TextBox
+ {
+ private Border _caret;
+
+ static ConsoleTextBox()
+ {
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(ConsoleTextBox), new FrameworkPropertyMetadata(typeof(ConsoleTextBox)));
+ }
+
+ public Brush CaretBottomBrush
+ {
+ get { return (Brush)GetValue(CaretBottomBrushProperty); }
+ set { SetValue(CaretBottomBrushProperty, value); }
+ }
+ public static readonly DependencyProperty CaretBottomBrushProperty =
+ DependencyProperty.Register("CaretBottomBrush", typeof(Brush), typeof(ConsoleTextBox), new PropertyMetadata(null));
+
+ public ConsoleTextBox()
+ {
+ SelectionChanged += (sender, e) => MoveCustomCaret();
+ LostFocus += (sender, e) => _caret.Visibility = Visibility.Collapsed;
+ GotKeyboardFocus += (sender, e) => _caret.Visibility = Visibility.Visible;
+ LostKeyboardFocus += (sender, e) => _caret.Visibility = Visibility.Collapsed;
+ }
+
+ public override void OnApplyTemplate()
+ {
+ base.OnApplyTemplate();
+
+ _caret = GetTemplateChild("PART_Caret") as Border;
+ }
+
+ private void MoveCustomCaret()
+ {
+ var caretLocation = GetRectFromCharacterIndex(CaretIndex).Location;
+
+ if (!double.IsInfinity(caretLocation.X))
+ {
+ Canvas.SetLeft(_caret, caretLocation.X);
+ }
+ }
+ }
+}