-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
DateExamples.xaml
297 lines (276 loc) · 19.3 KB
/
DateExamples.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
<UserControl x:Class="MetroDemo.ExampleViews.DateExamples"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:behaviors="clr-namespace:MetroDemo.Behaviors"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:globalization="clr-namespace:System.Globalization;assembly=mscorlib"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:local="clr-namespace:MetroDemo"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:markup="clr-namespace:MetroDemo.Markup"
d:DataContext="{d:DesignInstance local:MainWindowViewModel}"
d:DesignHeight="600"
d:DesignWidth="800"
mc:Ignorable="d">
<UserControl.Resources>
<Thickness x:Key="ColumnMargin">10 5 10 5</Thickness>
<Thickness x:Key="ControlMargin">0 5 0 0</Thickness>
</UserControl.Resources>
<AdornerDecorator>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Margin="{StaticResource ColumnMargin}">
<Label Content="Date picker" Style="{DynamicResource DescriptionHeaderStyle}" />
<DatePicker Width="200"
Margin="{StaticResource ControlMargin}"
HorizontalContentAlignment="Stretch"
mah:TextBoxHelper.ClearTextButton="True"
mah:TextBoxHelper.UseFloatingWatermark="True"
mah:TextBoxHelper.Watermark="Please select a date"
mah:TextBoxHelper.WatermarkAlignment="Right" />
<DatePicker Width="200"
Margin="{StaticResource ControlMargin}"
mah:ControlsHelper.IsReadOnly="True"
mah:TextBoxHelper.ClearTextButton="True"
SelectedDate="{x:Static system:DateTime.Now}" />
<DatePicker Width="200"
Margin="{StaticResource ControlMargin}"
mah:TextBoxHelper.ButtonCommand="{Binding ControlButtonCommand}"
mah:TextBoxHelper.ButtonCommandParameter="{Binding RelativeSource={RelativeSource Self}}"
mah:TextBoxHelper.Watermark="" />
<DatePicker Width="200"
Margin="{StaticResource ControlMargin}"
mah:TextBoxHelper.ButtonsAlignment="Left"
mah:TextBoxHelper.ClearTextButton="True"
mah:TextBoxHelper.Watermark="{x:Null}" />
<DatePicker Width="200"
Margin="{StaticResource ControlMargin}"
IsEnabled="False" />
<DatePicker Width="200"
Margin="{StaticResource ControlMargin}"
mah:TextBoxHelper.AutoWatermark="True"
SelectedDate="{Binding DatePickerDate}" />
<DatePicker Width="200"
Margin="{StaticResource ControlMargin}"
mah:TextBoxHelper.Watermark="Select a date"
FontSize="22"
SelectedDate="{Binding DatePickerDate, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True}">
<mah:TextBoxHelper.ButtonWidth>
<Binding Converter="{x:Static mah:FontSizeOffsetConverter.Instance}"
Path="FontSize"
RelativeSource="{RelativeSource Self}">
<Binding.ConverterParameter>
<system:Double>5</system:Double>
</Binding.ConverterParameter>
</Binding>
</mah:TextBoxHelper.ButtonWidth>
</DatePicker>
</StackPanel>
<StackPanel Grid.Column="1" Margin="{StaticResource ColumnMargin}">
<Label Content="Calendar" Style="{DynamicResource DescriptionHeaderStyle}" />
<CheckBox x:Name="IsTodayHighlightedCheckBox"
Margin="{StaticResource ControlMargin}"
Content="IsTodayHighlighted"
IsChecked="True" />
<Calendar Margin="{StaticResource ControlMargin}"
DisplayDateStart="{x:Static system:DateTime.Now}"
IsTodayHighlighted="{Binding ElementName=IsTodayHighlightedCheckBox, Path=IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
SelectionMode="MultipleRange" />
<Calendar Margin="{StaticResource ControlMargin}"
IsTodayHighlighted="{Binding ElementName=IsTodayHighlightedCheckBox, Path=IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
SelectionMode="MultipleRange" />
<Calendar Margin="{StaticResource ControlMargin}"
IsEnabled="False"
IsTodayHighlighted="{Binding ElementName=IsTodayHighlightedCheckBox, Path=IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
<StackPanel Grid.Column="2" Margin="{StaticResource ColumnMargin}">
<Label Content="DateTime/Time picker" Style="{DynamicResource DescriptionHeaderStyle}" />
<mah:DateTimePicker Margin="{StaticResource ControlMargin}">
<i:Interaction.Behaviors>
<behaviors:DateTimeNowBehavior />
</i:Interaction.Behaviors>
</mah:DateTimePicker>
<GroupBox Margin="{StaticResource ControlMargin}" Header="Try it yourself">
<StackPanel>
<CheckBox x:Name="DateTimePickerClearTextButton"
Margin="{StaticResource ControlMargin}"
Content="ClearTextButton" />
<CheckBox x:Name="DateTimePickerIsEnabled"
Margin="{StaticResource ControlMargin}"
Content="IsEnabled"
IsChecked="True" />
<CheckBox x:Name="DateTimePickerIsReadOnly"
Margin="{StaticResource ControlMargin}"
Content="IsReadOnly" />
<CheckBox x:Name="DateTimePickerIsClockVisible"
Margin="{StaticResource ControlMargin}"
Content="IsClockVisible"
IsChecked="True" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Label Grid.Row="0"
Grid.Column="0"
Margin="{StaticResource ControlMargin}"
Content="Orientation" />
<ComboBox Name="DateTimePickerOrientation"
Grid.Row="0"
Grid.Column="1"
Margin="{StaticResource ControlMargin}"
SelectedItem="{x:Static Orientation.Horizontal}">
<ComboBox.ItemsSource>
<x:Array Type="Orientation">
<Orientation>Vertical</Orientation>
<Orientation>Horizontal</Orientation>
</x:Array>
</ComboBox.ItemsSource>
</ComboBox>
<Label Grid.Row="1"
Grid.Column="0"
Margin="{StaticResource ControlMargin}"
Content="PickerVisibility" />
<ComboBox Name="DateTimePickerPickerVisibility"
Grid.Row="1"
Grid.Column="1"
Margin="{StaticResource ControlMargin}"
ItemsSource="{Binding Source={markup:EnumBindingSource {x:Type mah:TimePartVisibility}}, Mode=OneTime}"
SelectedItem="{x:Static mah:TimePartVisibility.All}" />
<Label Grid.Row="2"
Grid.Column="0"
Margin="{StaticResource ControlMargin}"
Content="HandVisibility" />
<ComboBox Name="DateTimePickerHandVisibility"
Grid.Row="2"
Grid.Column="1"
Margin="{StaticResource ControlMargin}"
ItemsSource="{Binding Source={markup:EnumBindingSource {x:Type mah:TimePartVisibility}}, Mode=OneTime}"
SelectedItem="{x:Static mah:TimePartVisibility.All}" />
<Label Grid.Row="3"
Grid.Column="0"
Margin="{StaticResource ControlMargin}"
Content="SelectedDateFormat" />
<ComboBox Name="DateTimePickerDateFormat"
Grid.Row="3"
Grid.Column="1"
Margin="{StaticResource ControlMargin}"
SelectedItem="{x:Static DatePickerFormat.Short}">
<ComboBox.ItemsSource>
<x:Array Type="DatePickerFormat">
<DatePickerFormat>Long</DatePickerFormat>
<DatePickerFormat>Short</DatePickerFormat>
</x:Array>
</ComboBox.ItemsSource>
</ComboBox>
<Label Grid.Row="4"
Grid.Column="0"
Margin="{StaticResource ControlMargin}"
Content="SelectedTimeFormat" />
<ComboBox Name="DateTimePickerTimeFormat"
Grid.Row="4"
Grid.Column="1"
Margin="{StaticResource ControlMargin}"
SelectedItem="{x:Static mah:TimePickerFormat.Long}">
<ComboBox.ItemsSource>
<x:Array Type="mah:TimePickerFormat">
<mah:TimePickerFormat>Long</mah:TimePickerFormat>
<mah:TimePickerFormat>Short</mah:TimePickerFormat>
</x:Array>
</ComboBox.ItemsSource>
</ComboBox>
<Label Grid.Row="5"
Grid.Column="0"
Margin="{StaticResource ControlMargin}"
Content="CultureInfo" />
<ComboBox Name="DateTimePickerCulture"
Grid.Row="5"
Grid.Column="1"
Margin="{StaticResource ControlMargin}"
mah:TextBoxHelper.ClearTextButton="True"
ItemsSource="{Binding CultureInfos, Mode=OneWay}"
SelectedItem="{Binding CurrentCulture, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<ComboBox.ItemTemplate>
<DataTemplate DataType="{x:Type globalization:CultureInfo}">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="1"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Text="{Binding DisplayName, Mode=OneWay}" />
<TextBlock Margin="1"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Text="{Binding IetfLanguageTag, Mode=OneWay, StringFormat='({0})'}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
<mah:DateTimePicker Margin="{StaticResource ControlMargin}"
mah:TextBoxHelper.ClearTextButton="{Binding Path=IsChecked, ElementName=DateTimePickerClearTextButton, Mode=TwoWay}"
mah:TextBoxHelper.UseFloatingWatermark="True"
Culture="{Binding CurrentCulture, Mode=OneWay}"
HandVisibility="{Binding Path=SelectedItem, ElementName=DateTimePickerHandVisibility, Mode=TwoWay}"
IsClockVisible="{Binding Path=IsChecked, ElementName=DateTimePickerIsClockVisible, Mode=TwoWay}"
IsEnabled="{Binding Path=IsChecked, ElementName=DateTimePickerIsEnabled, Mode=TwoWay}"
IsReadOnly="{Binding Path=IsChecked, ElementName=DateTimePickerIsReadOnly, Mode=TwoWay}"
Orientation="{Binding Path=SelectedItem, ElementName=DateTimePickerOrientation, Mode=TwoWay}"
PickerVisibility="{Binding Path=SelectedItem, ElementName=DateTimePickerPickerVisibility, Mode=TwoWay}"
SelectedDateFormat="{Binding Path=SelectedItem, ElementName=DateTimePickerDateFormat}"
SelectedTimeFormat="{Binding Path=SelectedItem, ElementName=DateTimePickerTimeFormat}" />
</StackPanel>
</GroupBox>
<GroupBox Margin="{StaticResource ControlMargin}" Header="Current time">
<AdornerDecorator>
<StackPanel>
<mah:DateTimePicker x:Name="DateTimePicker"
Margin="{StaticResource ControlMargin}"
mah:TextBoxHelper.ClearTextButton="{Binding Path=IsChecked, ElementName=DateTimePickerClearTextButton, Mode=TwoWay}"
Culture="{Binding CurrentCulture, Mode=OneWay}"
HandVisibility="{Binding Path=SelectedItem, ElementName=DateTimePickerHandVisibility, Mode=TwoWay}"
IsClockVisible="{Binding Path=IsChecked, ElementName=DateTimePickerIsClockVisible, Mode=TwoWay}"
IsEnabled="{Binding Path=IsChecked, ElementName=DateTimePickerIsEnabled, Mode=TwoWay}"
IsReadOnly="{Binding Path=IsChecked, ElementName=DateTimePickerIsReadOnly, Mode=TwoWay}"
Orientation="{Binding Path=SelectedItem, ElementName=DateTimePickerOrientation, Mode=TwoWay}"
PickerVisibility="{Binding Path=SelectedItem, ElementName=DateTimePickerPickerVisibility, Mode=TwoWay}"
SelectedDateFormat="{Binding Path=SelectedItem, ElementName=DateTimePickerDateFormat}"
SelectedTimeFormat="{Binding Path=SelectedItem, ElementName=DateTimePickerTimeFormat}">
<i:Interaction.Behaviors>
<behaviors:DateTimeNowBehavior />
</i:Interaction.Behaviors>
</mah:DateTimePicker>
<mah:TimePicker Margin="{StaticResource ControlMargin}"
mah:TextBoxHelper.ClearTextButton="{Binding Path=IsChecked, ElementName=DateTimePickerClearTextButton, Mode=TwoWay}"
Culture="{Binding CurrentCulture, Mode=OneWay}"
HandVisibility="{Binding Path=SelectedItem, ElementName=DateTimePickerHandVisibility, Mode=TwoWay}"
IsEnabled="{Binding Path=IsChecked, ElementName=DateTimePickerIsEnabled, Mode=TwoWay}"
IsReadOnly="{Binding Path=IsChecked, ElementName=DateTimePickerIsReadOnly, Mode=TwoWay}"
PickerVisibility="{Binding Path=SelectedItem, ElementName=DateTimePickerPickerVisibility, Mode=TwoWay}"
SelectedDateTime="{Binding Path=SelectedDateTime, ElementName=DateTimePicker}"
SelectedTimeFormat="{Binding Path=SelectedItem, ElementName=DateTimePickerTimeFormat}" />
<mah:TimePicker Margin="{StaticResource ControlMargin}"
mah:TextBoxHelper.AutoWatermark="True"
PickerVisibility="HourMinute"
SelectedDateTime="{Binding TimePickerDate, Mode=TwoWay, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True}"
SelectedTimeFormat="Short" />
</StackPanel>
</AdornerDecorator>
</GroupBox>
</StackPanel>
</Grid>
</AdornerDecorator>
</UserControl>