aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.SharedUI/Keyboard/TouchKeyboard.xaml.cs
blob: 66e084518f1fb6681f2c0a9cf7991c96bc67ab0a (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
81
82
83
84
85
86
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.SharedUI.Keyboard
{
    /// <summary>
    /// Interaction logic for TouchKeyboard.xaml
    /// </summary>
    public partial class TouchKeyboard : UserControl
    {
        public KeyboardDefinition CurrentKeyboardDefinition
        {
            get { return (KeyboardDefinition)GetValue(CurrentKeyboardDefinitionProperty); }
            set { SetValue(CurrentKeyboardDefinitionProperty, value); }
        }
        public static readonly DependencyProperty CurrentKeyboardDefinitionProperty =
            DependencyProperty.Register("CurrentKeyboardDefinition", typeof(KeyboardDefinition), typeof(TouchKeyboard), new PropertyMetadata(null));

        public Size KeySize
        {
            get { return (Size)GetValue(KeySizeProperty); }
            set { SetValue(KeySizeProperty, value); }
        }
        public static readonly DependencyProperty KeySizeProperty =
            DependencyProperty.Register("KeySize", typeof(Size), typeof(TouchKeyboard), new PropertyMetadata(Size.Empty));

        public KeysLineDefinition NumbersLineDefinition
        {
            get { return (KeysLineDefinition)GetValue(NumbersLineDefinitionProperty); }
            set { SetValue(NumbersLineDefinitionProperty, value); }
        }
        public static readonly DependencyProperty NumbersLineDefinitionProperty =
            DependencyProperty.Register("NumbersLineDefinition", typeof(KeysLineDefinition), typeof(TouchKeyboard), new PropertyMetadata(null));



        public TouchKeyboard()
        {
            LoadKeyboard();
            InitializeComponent();
            this.Loaded += (_, __) => LoadKeyboard();
            this.SizeChanged += (_, __) => SetKeySize();
        }

        private void LoadKeyboard()
        {
            var numbers = new KeysLineDefinition();

            for (int i = 1; i < 10; i++)
            {
                numbers.KeyDefinitions.Add(new KeyDefinition()
                {
                    StandardText = i.ToString(),
                });
            }

            numbers.KeyDefinitions.Add(new KeyDefinition()
            {
                StandardText = "0",
            });

            NumbersLineDefinition = numbers;

            CurrentKeyboardDefinition = KeyboardDefinition.Default;

            SetKeySize();
        }

        private void SetKeySize()
        {
            KeySize = new Size(ActualWidth / NumbersLineDefinition.KeyDefinitions.Count, (ActualWidth / NumbersLineDefinition.KeyDefinitions.Count) * 0.90);
        }
    }
}