aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Touch/Controls/TouchComboBox.cs
blob: 7a7c23b9163ac1b7cc72d14d46a2795921d7af84 (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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System;
using System.Collections;
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;
using Tango.Core.EventArguments;

namespace Tango.Touch.Controls
{
    public class TouchComboBox : Control
    {
        static TouchComboBox()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(TouchComboBox), new FrameworkPropertyMetadata(typeof(TouchComboBox)));
        }

        public String Watermark
        {
            get { return (String)GetValue(WatermarkProperty); }
            set { SetValue(WatermarkProperty, value); }
        }
        public static readonly DependencyProperty WatermarkProperty =
            DependencyProperty.Register("Watermark", typeof(String), typeof(TouchComboBox), new PropertyMetadata(null));

        public object SelectedItem
        {
            get { return (object)GetValue(SelectedItemProperty); }
            set { SetValue(SelectedItemProperty, value); }
        }
        public static readonly DependencyProperty SelectedItemProperty =
            DependencyProperty.Register("SelectedItem", typeof(object), typeof(TouchComboBox), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));

        public IList ItemsSource
        {
            get { return (IList)GetValue(ItemsSourceProperty); }
            set { SetValue(ItemsSourceProperty, value); }
        }
        public static readonly DependencyProperty ItemsSourceProperty =
            DependencyProperty.Register("ItemsSource", typeof(IList), typeof(TouchComboBox), new PropertyMetadata(null));

        public DataTemplate ItemTemplate
        {
            get { return (DataTemplate)GetValue(ItemTemplateProperty); }
            set { SetValue(ItemTemplateProperty, value); }
        }
        public static readonly DependencyProperty ItemTemplateProperty =
            DependencyProperty.Register("ItemTemplate", typeof(DataTemplate), typeof(TouchComboBox), new PropertyMetadata(null));

        public DataTemplate SelectedItemTemplate
        {
            get { return (DataTemplate)GetValue(SelectedItemTemplateProperty); }
            set { SetValue(SelectedItemTemplateProperty, value); }
        }
        public static readonly DependencyProperty SelectedItemTemplateProperty =
            DependencyProperty.Register("SelectedItemTemplate", typeof(DataTemplate), typeof(TouchComboBox), new PropertyMetadata(null));

        public String Title
        {
            get { return (String)GetValue(TitleProperty); }
            set { SetValue(TitleProperty, value); }
        }
        public static readonly DependencyProperty TitleProperty =
            DependencyProperty.Register("Title", typeof(String), typeof(TouchComboBox), new PropertyMetadata(null));

        public double MinPopupWidth
        {
            get { return (double)GetValue(MinPopupWidthProperty); }
            set { SetValue(MinPopupWidthProperty, value); }
        }
        public static readonly DependencyProperty MinPopupWidthProperty =
            DependencyProperty.Register("MinPopupWidth", typeof(double), typeof(TouchComboBox), new PropertyMetadata(300.0));

        public double MinPopupHeight
        {
            get { return (double)GetValue(MinPopupHeightProperty); }
            set { SetValue(MinPopupHeightProperty, value); }
        }
        public static readonly DependencyProperty MinPopupHeightProperty =
            DependencyProperty.Register("MinPopupHeight", typeof(double), typeof(TouchComboBox), new PropertyMetadata(200.0));

        public String DisplayMemberPath
        {
            get { return (String)GetValue(DisplayMemberPathProperty); }
            set { SetValue(DisplayMemberPathProperty, value); }
        }
        public static readonly DependencyProperty DisplayMemberPathProperty =
            DependencyProperty.Register("DisplayMemberPath", typeof(String), typeof(TouchComboBox), new PropertyMetadata(null));

        public String ValuePath
        {
            get { return (String)GetValue(ValuePathProperty); }
            set { SetValue(ValuePathProperty, value); }
        }
        public static readonly DependencyProperty ValuePathProperty =
            DependencyProperty.Register("ValuePath", typeof(String), typeof(TouchComboBox), new PropertyMetadata(null));



        public TouchComboBox()
        {
            this.RegisterForPreviewMouseOrTouchDown(OnMouseDown);
            this.RegisterForPreviewMouseOrTouchUp(OnMouseUp);
        }

        private void OnMouseUp(object sender, MouseOrTouchEventArgs e)
        {
            ShowSelectionOnTouchPanel();
        }

        private void OnMouseDown(object sender, MouseOrTouchEventArgs e)
        {
            System.Windows.Input.Keyboard.Focus(this);
        }

        private void ShowSelectionOnTouchPanel()
        {
            TouchPanel touchPanel = this.FindAncestor<TouchPanel>();

            if (touchPanel != null)
            {
                touchPanel.CurrentComboBox = this;
            }
        }

        internal void SetResultFromTouchPanel(Object selectedObject)
        {
            SelectedItem = selectedObject;
        }
    }
}