aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Touch/Controls/TouchStaticListBox.cs
blob: 023395006ba5167c1bcd4e5b49eb4e2b6204e5b0 (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
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.Commands;
using Tango.Core.EventArguments;

namespace Tango.Touch.Controls
{
    public class TouchStaticListBox : Control
    {
        public IList ItemsSource
        {
            get { return (IList)GetValue(ItemsSourceProperty); }
            set { SetValue(ItemsSourceProperty, value); }
        }
        public static readonly DependencyProperty ItemsSourceProperty =
            DependencyProperty.Register("ItemsSource", typeof(IList), typeof(TouchStaticListBox), 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(TouchStaticListBox), new PropertyMetadata(null));

        public Style ItemContainerStyle
        {
            get { return (Style)GetValue(ItemContainerStyleProperty); }
            set { SetValue(ItemContainerStyleProperty, value); }
        }
        public static readonly DependencyProperty ItemContainerStyleProperty =
            DependencyProperty.Register("ItemContainerStyle", typeof(Style), typeof(TouchStaticListBox), 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(TouchStaticListBox), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (d, e) => (d as TouchStaticListBox).OnSelectdItemChanged()));

        public RelayCommand<TouchStaticListBoxItem> ListBoxItemLoadedCommand
        {
            get { return (RelayCommand<TouchStaticListBoxItem>)GetValue(ListBoxItemLoadedCommandProperty); }
            set { SetValue(ListBoxItemLoadedCommandProperty, value); }
        }
        public static readonly DependencyProperty ListBoxItemLoadedCommandProperty =
            DependencyProperty.Register("ListBoxItemLoadedCommand", typeof(RelayCommand<TouchStaticListBoxItem>), typeof(TouchStaticListBox), new PropertyMetadata(null));

        public ItemsPanelTemplate ItemsPanel
        {
            get { return (ItemsPanelTemplate)GetValue(ItemsPanelProperty); }
            set { SetValue(ItemsPanelProperty, value); }
        }
        public static readonly DependencyProperty ItemsPanelProperty =
            DependencyProperty.Register("ItemsPanel", typeof(ItemsPanelTemplate), typeof(TouchStaticListBox), new PropertyMetadata(null));



        static TouchStaticListBox()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(TouchStaticListBox), new FrameworkPropertyMetadata(typeof(TouchStaticListBox)));
        }

        public TouchStaticListBox()
        {
            ListBoxItemLoadedCommand = new RelayCommand<TouchStaticListBoxItem>(RegisterListBoxItemEvents);
            Loaded += TouchStaticListBox_Loaded;
        }

        private void TouchStaticListBox_Loaded(object sender, RoutedEventArgs e)
        {
            OnSelectdItemChanged();
        }

        private void RegisterListBoxItemEvents(TouchStaticListBoxItem item)
        {
            if (item.Tag == null)
            {
                item.Tag = 1;
                item.RegisterForPreviewMouseOrTouchUp(OnItemMouseUp);
            }
        }

        private void OnItemMouseUp(object sender, MouseOrTouchEventArgs e)
        {
            var scrollViewer = this.FindAncestor<LightTouchScrollViewer>();
            if (scrollViewer != null && scrollViewer.IsAfterScrolling) return;

            var item = (e.Source is TouchStaticListBoxItem) ? e.Source as TouchStaticListBoxItem : (e.Source as DependencyObject).FindAncestor<TouchStaticListBoxItem>();
            SelectedItem = item.DataContext;
        }

        private void OnSelectdItemChanged()
        {
            var items = GetItems();
            items.ForEach(x => x.IsSelected = false);

            if (SelectedItem != null)
            {
                var selected_item = items.FirstOrDefault(x => SelectedItem.Equals(x.DataContext));

                if (selected_item != null)
                {
                    selected_item.IsSelected = true;
                }
            }
        }

        private List<TouchStaticListBoxItem> GetItems()
        {
            return this.FindVisualChildren<TouchStaticListBoxItem>().ToList();
        }
    }
}
void SharedDtor(); void SetCachedSize(int size) const PROTOBUF_FINAL; void InternalSwap(UploadHardwareConfigurationRequest* other); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return NULL; } inline void* MaybeArenaPtr() const { return NULL; } public: ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL; // nested types ---------------------------------------------------- // accessors ------------------------------------------------------- // .Tango.PMR.Hardware.HardwareConfiguration HardwareConfiguration = 1; bool has_hardwareconfiguration() const; void clear_hardwareconfiguration(); static const int kHardwareConfigurationFieldNumber = 1; const ::Tango::PMR::Hardware::HardwareConfiguration& hardwareconfiguration() const; ::Tango::PMR::Hardware::HardwareConfiguration* mutable_hardwareconfiguration(); ::Tango::PMR::Hardware::HardwareConfiguration* release_hardwareconfiguration(); void set_allocated_hardwareconfiguration(::Tango::PMR::Hardware::HardwareConfiguration* hardwareconfiguration); // @@protoc_insertion_point(class_scope:Tango.PMR.Hardware.UploadHardwareConfigurationRequest) private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::Tango::PMR::Hardware::HardwareConfiguration* hardwareconfiguration_; mutable int _cached_size_; friend struct protobuf_UploadHardwareConfigurationRequest_2eproto::TableStruct; }; // =================================================================== // =================================================================== #if !PROTOBUF_INLINE_NOT_IN_HEADERS #ifdef __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif // __GNUC__ // UploadHardwareConfigurationRequest // .Tango.PMR.Hardware.HardwareConfiguration HardwareConfiguration = 1; inline bool UploadHardwareConfigurationRequest::has_hardwareconfiguration() const { return this != internal_default_instance() && hardwareconfiguration_ != NULL; } inline void UploadHardwareConfigurationRequest::clear_hardwareconfiguration() { if (GetArenaNoVirtual() == NULL && hardwareconfiguration_ != NULL) delete hardwareconfiguration_; hardwareconfiguration_ = NULL; } inline const ::Tango::PMR::Hardware::HardwareConfiguration& UploadHardwareConfigurationRequest::hardwareconfiguration() const { const ::Tango::PMR::Hardware::HardwareConfiguration* p = hardwareconfiguration_; // @@protoc_insertion_point(field_get:Tango.PMR.Hardware.UploadHardwareConfigurationRequest.HardwareConfiguration) return p != NULL ? *p : *reinterpret_cast<const ::Tango::PMR::Hardware::HardwareConfiguration*>( &::Tango::PMR::Hardware::_HardwareConfiguration_default_instance_); } inline ::Tango::PMR::Hardware::HardwareConfiguration* UploadHardwareConfigurationRequest::mutable_hardwareconfiguration() { if (hardwareconfiguration_ == NULL) { hardwareconfiguration_ = new ::Tango::PMR::Hardware::HardwareConfiguration; } // @@protoc_insertion_point(field_mutable:Tango.PMR.Hardware.UploadHardwareConfigurationRequest.HardwareConfiguration) return hardwareconfiguration_; } inline ::Tango::PMR::Hardware::HardwareConfiguration* UploadHardwareConfigurationRequest::release_hardwareconfiguration() { // @@protoc_insertion_point(field_release:Tango.PMR.Hardware.UploadHardwareConfigurationRequest.HardwareConfiguration) ::Tango::PMR::Hardware::HardwareConfiguration* temp = hardwareconfiguration_; hardwareconfiguration_ = NULL; return temp; } inline void UploadHardwareConfigurationRequest::set_allocated_hardwareconfiguration(::Tango::PMR::Hardware::HardwareConfiguration* hardwareconfiguration) { delete hardwareconfiguration_; hardwareconfiguration_ = hardwareconfiguration; if (hardwareconfiguration) { } else { } // @@protoc_insertion_point(field_set_allocated:Tango.PMR.Hardware.UploadHardwareConfigurationRequest.HardwareConfiguration) } #ifdef __GNUC__ #pragma GCC diagnostic pop #endif // __GNUC__ #endif // !PROTOBUF_INLINE_NOT_IN_HEADERS // @@protoc_insertion_point(namespace_scope) } // namespace Hardware } // namespace PMR } // namespace Tango // @@protoc_insertion_point(global_scope) #endif // PROTOBUF_UploadHardwareConfigurationRequest_2eproto__INCLUDED