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
|
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;
using Tango.Core.ExtensionMethods;
namespace Tango.Touch.Controls
{
public class TouchNativeListBox : ListBox
{
/// <summary>
/// Gets or sets the ripple factor.
/// </summary>
public double RippleFactor
{
get { return (double)GetValue(RippleFactorProperty); }
set { SetValue(RippleFactorProperty, value); }
}
public static readonly DependencyProperty RippleFactorProperty =
DependencyProperty.Register("RippleFactor", typeof(double), typeof(TouchNativeListBox), new PropertyMetadata(30.0));
/// <summary>
/// Gets or sets a value indicating whether to prevent selection on mouse down.
/// </summary>
public bool PreventTouchDownSelect
{
get { return (bool)GetValue(PreventTouchDownSelectProperty); }
set { SetValue(PreventTouchDownSelectProperty, value); }
}
public static readonly DependencyProperty PreventTouchDownSelectProperty =
DependencyProperty.Register("PreventTouchDownSelect", typeof(bool), typeof(TouchNativeListBox), new PropertyMetadata(true));
/// <summary>
/// Gets or sets the scroll viewer.
/// </summary>
public LightTouchScrollViewer ScrollViewer
{
get { return (LightTouchScrollViewer)GetValue(ScrollViewerProperty); }
set { SetValue(ScrollViewerProperty, value); }
}
public static readonly DependencyProperty ScrollViewerProperty =
DependencyProperty.Register("ScrollViewer", typeof(LightTouchScrollViewer), typeof(TouchNativeListBox), new PropertyMetadata(null));
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
ScrollViewer = GetTemplateChild("PART_ScrollViewer") as LightTouchScrollViewer;
}
protected override void OnMouseUp(MouseButtonEventArgs e)
{
if (ScrollViewer.IsAfterScrolling) return;
if (e.ChangedButton == MouseButton.Left)
{
DependencyObject obj = this.ContainerFromElement((Visual)e.OriginalSource);
if (obj != null)
{
FrameworkElement element = obj as FrameworkElement;
if (element != null)
{
if (String.IsNullOrWhiteSpace(SelectedValuePath))
{
ListBoxItem item = element as ListBoxItem;
if (item != null)
{
this.SelectedItem = item.DataContext;
}
}
else
{
object context = element.DataContext;
if (context != null)
{
SelectedValue = context.GetPropertyValueByPath(SelectedValuePath);
}
}
}
}
}
}
protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
{
if (PreventTouchDownSelect)
{
e.Handled = true;
}
}
static TouchNativeListBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(TouchNativeListBox), new FrameworkPropertyMetadata(typeof(TouchNativeListBox)));
}
}
}
|