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
|
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.Controls.Primitives;
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.Touch.Controls
{
public class TouchToggleButton : ToggleButton, ITouchControl
{
private Object _uncheckedContent;
private bool _loaded;
private bool first_checked;
#region ITouchControl
public CornerRadius CornerRadius
{
get { return (CornerRadius)GetValue(CornerRadiusProperty); }
set { SetValue(CornerRadiusProperty, value); }
}
public static readonly DependencyProperty CornerRadiusProperty =
DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(TouchToggleButton), new PropertyMetadata(new CornerRadius()));
public bool EnableDropShadow
{
get { return (bool)GetValue(EnableDropShadowProperty); }
set { SetValue(EnableDropShadowProperty, value); }
}
public static readonly DependencyProperty EnableDropShadowProperty =
DependencyProperty.Register("EnableDropShadow", typeof(bool), typeof(TouchToggleButton), new PropertyMetadata(true));
public double BlurRadius
{
get { return (double)GetValue(BlurRadiusProperty); }
set { SetValue(BlurRadiusProperty, value); }
}
public static readonly DependencyProperty BlurRadiusProperty =
DependencyProperty.Register("BlurRadius", typeof(double), typeof(TouchToggleButton), new PropertyMetadata(10.0));
public double ShadowDepth
{
get { return (double)GetValue(ShadowDepthProperty); }
set { SetValue(ShadowDepthProperty, value); }
}
public static readonly DependencyProperty ShadowDepthProperty =
DependencyProperty.Register("ShadowDepth", typeof(double), typeof(TouchToggleButton), new PropertyMetadata(1.0));
public Color ShadowColor
{
get { return (Color)GetValue(ShadowColorProperty); }
set { SetValue(ShadowColorProperty, value); }
}
public static readonly DependencyProperty ShadowColorProperty =
DependencyProperty.Register("ShadowColor", typeof(Color), typeof(TouchToggleButton), new PropertyMetadata(Colors.Gray));
public Brush RippleBrush
{
get { return (Brush)GetValue(RippleBrushProperty); }
set { SetValue(RippleBrushProperty, value); }
}
public static readonly DependencyProperty RippleBrushProperty =
DependencyProperty.Register("RippleBrush", typeof(Brush), typeof(TouchToggleButton), new PropertyMetadata(null));
#endregion
public Object CheckedContent
{
get { return (Object)GetValue(CheckedContentProperty); }
set { SetValue(CheckedContentProperty, value); }
}
public static readonly DependencyProperty CheckedContentProperty =
DependencyProperty.Register("CheckedContent", typeof(Object), typeof(TouchToggleButton), new PropertyMetadata(null));
static TouchToggleButton()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(TouchToggleButton), new FrameworkPropertyMetadata(typeof(TouchToggleButton)));
}
public TouchToggleButton()
{
Loaded += (_, __) =>
{
if (!_loaded)
{
_uncheckedContent = Content;
_loaded = true;
}
};
Checked += (_, __) =>
{
if (_loaded)
{
Content = CheckedContent != null ? CheckedContent : Content;
}
else
{
Loaded += (x, y) =>
{
if (!first_checked)
{
Content = CheckedContent != null ? CheckedContent : Content;
first_checked = true;
}
};
}
};
Unchecked += (_, __) => Content = _uncheckedContent;
}
}
}
|