/
NumberBox.xaml
426 lines (403 loc) · 28.3 KB
/
NumberBox.xaml
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. -->
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="http://schemas.modernwpf.com/2019"
xmlns:local="clr-namespace:ModernWpf.Controls">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/ModernWpf;component/Styles/RepeatButton.xaml" />
<ResourceDictionary Source="/ModernWpf;component/Styles/TextBox.xaml" />
</ResourceDictionary.MergedDictionaries>
<ui:CornerRadiusFilterConverter x:Key="LeftCornerRadiusFilterConverter" Filter="Left" />
<ui:CornerRadiusFilterConverter x:Key="RightCornerRadiusFilterConverter" Filter="Right" />
<Thickness x:Key="NumberBoxPopupIndicatorMargin">0,0,8,0</Thickness>
<Style x:Key="NumberBoxSpinButtonStyle" TargetType="RepeatButton" BasedOn="{StaticResource DefaultRepeatButtonStyle}">
<Style.Setters>
<Setter Property="IsTabStop" Value="False" />
<Setter Property="MinWidth" Value="34" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="Background" Value="{DynamicResource TextControlBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource TextControlBorderBrush}" />
<Setter Property="BorderThickness" Value="{DynamicResource NumberBoxSpinButtonBorderThickness}" />
<Setter Property="FontFamily" Value="{DynamicResource SymbolThemeFontFamily}" />
</Style.Setters>
</Style>
<Style x:Key="NumberBoxPopupSpinButtonStyle" TargetType="RepeatButton" BasedOn="{StaticResource DefaultRepeatButtonStyle}">
<Style.Setters>
<Setter Property="Focusable" Value="False" />
<Setter Property="Width" Value="40" />
<Setter Property="Height" Value="32" />
<Setter Property="Background" Value="{DynamicResource TextControlBackground}" />
<Setter Property="BorderThickness" Value="{DynamicResource NumberBoxPopupSpinButtonBorderThickness}" />
<Setter Property="FontFamily" Value="{DynamicResource SymbolThemeFontFamily}" />
</Style.Setters>
</Style>
<Style x:Key="NumberBoxTextBoxStyle" TargetType="TextBox" BasedOn="{StaticResource DefaultTextBoxStyle}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<ControlTemplate.Resources>
<Style x:Key="DeleteButtonStyle" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border
x:Name="ButtonLayoutGrid"
BorderBrush="{DynamicResource TextControlButtonBorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{DynamicResource TextControlButtonBackground}"
CornerRadius="{TemplateBinding ui:ControlHelper.CornerRadius}">
<TextBlock
x:Name="GlyphElement"
Foreground="{DynamicResource TextControlButtonForeground}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
FontStyle="Normal"
FontSize="12"
Text=""
FontFamily="{DynamicResource SymbolThemeFontFamily}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" TargetName="ButtonLayoutGrid" Value="{DynamicResource TextControlButtonBackgroundPointerOver}" />
<Setter Property="BorderBrush" TargetName="ButtonLayoutGrid" Value="{DynamicResource TextControlButtonBorderBrushPointerOver}" />
<Setter Property="Foreground" TargetName="GlyphElement" Value="{DynamicResource TextControlButtonForegroundPointerOver}" />
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter Property="Background" TargetName="ButtonLayoutGrid" Value="{DynamicResource TextControlButtonBackgroundPressed}" />
<Setter Property="BorderBrush" TargetName="ButtonLayoutGrid" Value="{DynamicResource TextControlButtonBorderBrushPressed}" />
<Setter Property="Foreground" TargetName="GlyphElement" Value="{DynamicResource TextControlButtonForegroundPressed}" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Opacity" TargetName="ButtonLayoutGrid" Value="0" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ControlTemplate.Resources>
<Grid SnapsToDevicePixels="True">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="ButtonStates">
<VisualState x:Name="ButtonVisible">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="DeleteButton" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="ButtonCollapsed" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ui:ContentPresenterEx
x:Name="HeaderContentPresenter"
Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="2"
Content="{TemplateBinding ui:ControlHelper.Header}"
ContentTemplate="{TemplateBinding ui:ControlHelper.HeaderTemplate}"
FontWeight="Normal"
Foreground="{DynamicResource TextControlHeaderForeground}"
Margin="{DynamicResource TextBoxTopHeaderMargin}"
TextWrapping="Wrap"
VerticalAlignment="Top"
Visibility="{TemplateBinding ui:ControlHelper.HeaderVisibility}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<!-- Control.IsTemplateFocusTarget="True" -->
<Border
x:Name="BorderElement"
Grid.Row="1"
Grid.Column="0"
Grid.RowSpan="1"
Grid.ColumnSpan="3"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding ui:ControlHelper.CornerRadius}"
MinWidth="{TemplateBinding MinWidth}"
MinHeight="{TemplateBinding MinHeight}"
ui:ValidationHelper.IsTemplateValidationAdornerSite="True" />
<ScrollViewer
x:Name="PART_ContentHost"
Grid.Row="1"
Grid.Column="0"
Style="{DynamicResource TextControlContentHostStyle}"
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
Margin="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
IsTabStop="False"
Focusable="False" />
<TextBlock
x:Name="PlaceholderTextContentPresenter"
Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="2"
Foreground="{TemplateBinding ui:ControlHelper.PlaceholderForeground}"
Margin="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
Text="{TemplateBinding ui:ControlHelper.PlaceholderText}"
TextAlignment="{TemplateBinding TextAlignment}"
TextWrapping="{TemplateBinding TextWrapping}"
IsHitTestVisible="False" />
<Button
x:Name="DeleteButton"
Grid.Row="1"
Grid.Column="1"
Focusable="False"
Style="{StaticResource DeleteButtonStyle}"
BorderThickness="{TemplateBinding BorderThickness}"
ui:ControlHelper.CornerRadius="{TemplateBinding ui:ControlHelper.CornerRadius, Converter={StaticResource RightCornerRadiusFilterConverter}}"
Padding="{DynamicResource HelperButtonThemePadding}"
IsTabStop="False"
Visibility="Collapsed"
FontSize="{TemplateBinding FontSize}"
MinWidth="34"
VerticalAlignment="Stretch"
ui:TextBoxHelper.IsDeleteButton="True" />
<ContentPresenter
x:Name="DescriptionPresenter"
Grid.Row="2"
Grid.Column="0"
Grid.ColumnSpan="2"
Content="{TemplateBinding ui:ControlHelper.Description}"
Visibility="{TemplateBinding ui:ControlHelper.DescriptionVisibility}"
TextElement.Foreground="{DynamicResource SystemControlDescriptionTextForegroundBrush}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<TextBlock
Grid.Row="1"
Grid.Column="2"
Margin="{StaticResource NumberBoxPopupIndicatorMargin}"
Foreground="{DynamicResource NumberBoxPopupIndicatorForeground}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
FontSize="12"
Text=""
FontFamily="{DynamicResource SymbolThemeFontFamily}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="ui:ControlHelper.PlaceholderForeground" Value="{x:Null}">
<Setter TargetName="PlaceholderTextContentPresenter" Property="Foreground" Value="{DynamicResource TextControlPlaceholderForeground}" />
</Trigger>
<Trigger Property="ui:TextBoxHelper.HasText" Value="True">
<Setter TargetName="PlaceholderTextContentPresenter" Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="HeaderContentPresenter" Property="Foreground" Value="{DynamicResource TextControlHeaderForegroundDisabled}" />
<Setter Property="Background" Value="{DynamicResource TextControlBackgroundDisabled}" />
<Setter TargetName="BorderElement" Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushDisabled}" />
<Setter Property="Foreground" Value="{DynamicResource TextControlForegroundDisabled}" />
<Setter TargetName="PlaceholderTextContentPresenter" Property="Foreground" Value="{DynamicResource TextControlPlaceholderForegroundDisabled}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="BorderElement" Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushPointerOver}" />
<Setter Property="Background" Value="{DynamicResource TextControlBackgroundPointerOver}" />
<Setter TargetName="PlaceholderTextContentPresenter" Property="Foreground" Value="{DynamicResource TextControlPlaceholderForegroundPointerOver}" />
<Setter Property="Foreground" Value="{DynamicResource TextControlForegroundPointerOver}" />
</Trigger>
<Trigger Property="IsSelectionActive" Value="true">
<Setter TargetName="PlaceholderTextContentPresenter" Property="Foreground" Value="{DynamicResource TextControlPlaceholderForegroundFocused}" />
<Setter Property="Background" Value="{DynamicResource TextControlBackgroundFocused}" />
<Setter TargetName="BorderElement" Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushFocused}" />
<Setter TargetName="BorderElement" Property="BorderThickness" Value="{DynamicResource TextControlBorderThemeThicknessFocused}" />
<Setter Property="Foreground" Value="{DynamicResource TextControlForegroundFocused}" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsKeyboardFocused" Value="True" />
<Condition Property="ui:TextBoxHelper.HasText" Value="True" />
<Condition Property="IsReadOnly" Value="False" />
<Condition Property="AcceptsReturn" Value="False" />
<Condition Property="TextWrapping" Value="NoWrap" />
</MultiTrigger.Conditions>
<Setter Property="ui:TextBoxHelper.IsDeleteButtonVisible" Value="True" />
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="local:NumberBox">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="SelectionBrush" Value="{DynamicResource TextControlSelectionHighlightColor}" />
<Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:NumberBox">
<Grid ui:ThemeManager.HasThemeResources="True">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="SpinButtonStates">
<VisualState x:Name="SpinButtonsCollapsed" />
<VisualState x:Name="SpinButtonsVisible" />
<VisualState x:Name="SpinButtonsPopup" />
</VisualStateGroup>
<VisualStateGroup x:Name="UpSpinButtonEnabledStates">
<VisualState x:Name="UpSpinButtonEnabled" />
<VisualState x:Name="UpSpinButtonDisabled">
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="UpSpinButton" Storyboard.TargetProperty="IsEnabled">
<DiscreteBooleanKeyFrame KeyTime="0" Value="False" />
</BooleanAnimationUsingKeyFrames>
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="PopupUpSpinButton" Storyboard.TargetProperty="IsEnabled">
<DiscreteBooleanKeyFrame KeyTime="0" Value="False" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
<ui:VisualStateGroupEx x:Name="DownSpinButtonEnabledStates">
<VisualState x:Name="DownSpinButtonEnabled" />
<VisualState x:Name="DownSpinButtonDisabled">
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="DownSpinButton" Storyboard.TargetProperty="IsEnabled">
<DiscreteBooleanKeyFrame KeyTime="0" Value="False" />
</BooleanAnimationUsingKeyFrames>
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="PopupDownSpinButton" Storyboard.TargetProperty="IsEnabled">
<DiscreteBooleanKeyFrame KeyTime="0" Value="False" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</ui:VisualStateGroupEx>
</VisualStateManager.VisualStateGroups>
<Grid.Resources>
<ui:ResourceDictionaryEx>
<ui:ResourceDictionaryEx.ThemeDictionaries>
<ResourceDictionary x:Key="Light" ui:ThemeDictionary.Key="Light">
<ui:StaticResource x:Key="RepeatButtonBorderBrushPointerOver" ResourceKey="TextControlBorderBrush" />
<ui:StaticResource x:Key="RepeatButtonBorderBrushPressed" ResourceKey="TextControlBorderBrush" />
</ResourceDictionary>
<ResourceDictionary x:Key="Dark" ui:ThemeDictionary.Key="Dark">
<ui:StaticResource x:Key="RepeatButtonBorderBrushPointerOver" ResourceKey="TextControlBorderBrush" />
<ui:StaticResource x:Key="RepeatButtonBorderBrushPressed" ResourceKey="TextControlBorderBrush" />
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrast" ui:ThemeDictionary.Key="HighContrast">
<ui:StaticResource x:Key="RepeatButtonBorderBrushPointerOver" ResourceKey="SystemControlHighlightBaseMediumLowBrush" />
<ui:StaticResource x:Key="RepeatButtonBorderBrushPressed" ResourceKey="SystemControlHighlightTransparentBrush" />
</ResourceDictionary>
</ui:ResourceDictionaryEx.ThemeDictionaries>
</ui:ResourceDictionaryEx>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ui:ContentPresenterEx
x:Name="HeaderContentPresenter"
Grid.ColumnSpan="3"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
FontWeight="Normal"
Foreground="{DynamicResource TextControlHeaderForeground}"
Margin="{DynamicResource TextBoxTopHeaderMargin}"
TextWrapping="Wrap"
VerticalAlignment="Top"
Visibility="Collapsed"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<TextBox
x:Name="InputBox"
Grid.Row="1"
ui:ControlHelper.PlaceholderText="{TemplateBinding PlaceholderText}"
SelectionBrush="{TemplateBinding SelectionBrush}"
ui:ControlHelper.CornerRadius="{TemplateBinding CornerRadius}" />
<Popup
x:Name="UpDownPopup"
Grid.Row="1"
Grid.Column="1"
AllowsTransparency="True"
Placement="Right"
VerticalOffset="{DynamicResource NumberBoxPopupVerticalOffset}"
HorizontalOffset="{DynamicResource NumberBoxPopupHorizonalOffset}"
HorizontalAlignment="Left">
<ui:ThemeShadowChrome
CornerRadius="{DynamicResource OverlayCornerRadius}"
Depth="{DynamicResource NumberBoxPopupShadowDepth}"
IsShadowEnabled="{DynamicResource {x:Static SystemParameters.DropShadowKey}}">
<Border
x:Name="PopupContentRoot"
Background="{DynamicResource SystemControlBackgroundAltHighBrush}"
BorderBrush="{DynamicResource ToolTipBorderBrush}"
BorderThickness="{DynamicResource ToolTipBorderThemeThickness}"
CornerRadius="{DynamicResource OverlayCornerRadius}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<RepeatButton
x:Name="PopupUpSpinButton"
Style="{StaticResource NumberBoxPopupSpinButtonStyle}"
Content="" />
<RepeatButton
x:Name="PopupDownSpinButton"
Style="{StaticResource NumberBoxPopupSpinButtonStyle}"
Grid.Row="1"
Content="" />
</Grid>
</Border>
</ui:ThemeShadowChrome>
</Popup>
<RepeatButton
x:Name="UpSpinButton"
Grid.Row="1"
Grid.Column="1"
Visibility="Collapsed"
FontSize="{TemplateBinding FontSize}"
Content=""
Style="{StaticResource NumberBoxSpinButtonStyle}"
ui:ControlHelper.CornerRadius="0" />
<RepeatButton
x:Name="DownSpinButton"
Grid.Row="1"
Grid.Column="2"
Visibility="Collapsed"
FontSize="{TemplateBinding FontSize}"
Content=""
Style="{StaticResource NumberBoxSpinButtonStyle}"
ui:ControlHelper.CornerRadius="{TemplateBinding CornerRadius, Converter={StaticResource RightCornerRadiusFilterConverter}}" />
<ContentPresenter
x:Name="DescriptionPresenter"
Grid.Row="2"
Grid.ColumnSpan="2"
Content="{TemplateBinding Description}"
TextElement.Foreground="{DynamicResource SystemControlDescriptionTextForegroundBrush}"
Visibility="{TemplateBinding ui:ControlHelper.DescriptionVisibility}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="HeaderContentPresenter" Property="Foreground" Value="{DynamicResource TextControlHeaderForegroundDisabled}" />
</Trigger>
<!-- SpinButtonsVisible -->
<Trigger Property="SpinButtonPlacementMode" Value="Inline">
<Setter TargetName="DownSpinButton" Property="Visibility" Value="Visible" />
<Setter TargetName="UpSpinButton" Property="Visibility" Value="Visible" />
<Setter TargetName="InputBox" Property="ui:ControlHelper.CornerRadius" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=CornerRadius, Converter={StaticResource LeftCornerRadiusFilterConverter}}" />
</Trigger>
<!-- SpinButtonsPopup -->
<Trigger Property="SpinButtonPlacementMode" Value="Compact">
<Setter TargetName="InputBox" Property="Style" Value="{StaticResource NumberBoxTextBoxStyle}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>