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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
<UserControl x:Class="HandBrakeWPF.Controls.NumberBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Loaded="UserControl_Loaded">
<UserControl.Resources>
<Style x:Key="Arrow" TargetType="Polygon">
<Setter Property="Fill" Value="#333" />
</Style>
<!-- UpButton and DownButton are identical except for the border radius in the control template.
We can't pass that through so we need to duplicate the template. After a change is made from one button
template it should be copied to the other. -->
<Style x:Key="UpButton" TargetType="Button">
<Setter Property="Margin" Value="0"/>
<Setter Property="Background" >
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1" >
<GradientStop Color="#EEE" Offset="0.4"/>
<GradientStop Color="#BBB" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border
Name="border"
BorderThickness="1"
BorderBrush="#888"
CornerRadius="0,2,0,0"
Background="{TemplateBinding Background}">
<ContentPresenter
Name="content"
HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="#FF4788c8" />
<Setter Property="Foreground" Value="#FF4788c8" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" >
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1" >
<GradientStop Color="#CCC" Offset="0.4"/>
<GradientStop Color="#999" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter TargetName="content" Property="RenderTransform" >
<Setter.Value>
<TranslateTransform Y="1.0" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsDefaulted" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="#FF282828" />
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="#FF282828" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="border" Property="Opacity" Value="0.7" />
<Setter Property="Foreground" Value="Gray" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="DownButton" TargetType="Button">
<Setter Property="Margin" Value="0"/>
<Setter Property="Background" >
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1" >
<GradientStop Color="#EEE" Offset="0.4"/>
<GradientStop Color="#BBB" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border
Name="border"
BorderThickness="1"
BorderBrush="#888"
CornerRadius="0,0,2,0"
Background="{TemplateBinding Background}">
<ContentPresenter
Name="content"
HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="#FF4788c8" />
<Setter Property="Foreground" Value="#FF4788c8" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" >
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1" >
<GradientStop Color="#CCC" Offset="0.4"/>
<GradientStop Color="#999" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter TargetName="content" Property="RenderTransform" >
<Setter.Value>
<TranslateTransform Y="1.0" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsDefaulted" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="#FF282828" />
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="#FF282828" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="border" Property="Opacity" Value="0.7" />
<Setter Property="Foreground" Value="Gray" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBox
Name="numberBox"
Grid.Column="0"
GotFocus="NumberBoxGotFocus"
LostFocus="NumberBoxLostFocus"
PreviewTextInput="NumberBoxPreviewTextInput"
PreviewKeyDown="NumberBoxPreviewKeyDown"
PreviewMouseDown="NumberBoxPreviewMouseDown"
PreviewMouseUp="NumberBoxPreviewMouseUp"
TextChanged="NumberBoxTextChanged"
VerticalContentAlignment="Center"/>
<Grid
Name="incrementButtonsGrid"
Grid.Column="1"
Width="16">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button AutomationProperties.Name="Increase Number"
Style="{StaticResource UpButton}" IsTabStop="False"
Grid.Row="0"
FontSize="4"
PreviewMouseLeftButtonDown="UpButtonMouseLeftButtonDown"
PreviewMouseLeftButtonUp="UpButtonMouseLeftButtonUp">
<Polygon
Style="{StaticResource Arrow}"
Points="4,0 0,4 8,4" />
</Button>
<Button AutomationProperties.Name="Decrease Number"
Style="{StaticResource DownButton}" IsTabStop="False"
Grid.Row="1"
FontSize="4"
PreviewMouseLeftButtonDown="DownButtonMouseLeftButtonDown"
PreviewMouseLeftButtonUp="DownButtonMouseLeftButtonUp">
<Polygon
Style="{StaticResource Arrow}"
Points="0,0 8,0 4,4" />
</Button>
</Grid>
</Grid>
</UserControl>
|