@@ -103,10 +103,22 @@ public string DateFormat
103
103
104
104
private static void OnStartDateChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
105
105
{
106
+ var ctrl = d as DateRangePicker ;
107
+ if ( ctrl != null && ctrl . _textBoxStart != null )
108
+ {
109
+ ctrl . _textBoxStart . Text = e . NewValue ? . ToString ( ) ;
110
+ ctrl . UpdateStartDateFromTextBox ( ) ;
111
+ }
106
112
}
107
113
108
114
private static void OnEndDateChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
109
115
{
116
+ var ctrl = d as DateRangePicker ;
117
+ if ( ctrl != null && ctrl . _textBoxEnd != null )
118
+ {
119
+ ctrl . _textBoxEnd . Text = e . NewValue ? . ToString ( ) ;
120
+ ctrl . UpdateEndDateFromTextBox ( ) ;
121
+ }
110
122
}
111
123
112
124
@@ -171,10 +183,29 @@ public override void OnApplyTemplate()
171
183
Loaded += DateRangePicker_Loaded ;
172
184
}
173
185
186
+ private void OnBorder_PreviewMouseUp ( object sender , MouseButtonEventArgs e )
187
+ {
188
+ if ( e . OriginalSource is Button button )
189
+ return ;
190
+ if ( _popup != null && ! _popup . IsOpen )
191
+ _popup . IsOpen = true ;
192
+ }
193
+
174
194
private void TextBoxEnd_TextChanged ( object sender , TextChangedEventArgs e )
195
+ {
196
+ UpdateEndDateFromTextBox ( ) ;
197
+ }
198
+
199
+ void UpdateEndDateFromTextBox ( )
175
200
{
176
201
if ( _textBoxEnd != null )
177
202
{
203
+ if ( string . IsNullOrWhiteSpace ( _textBoxEnd . Text ) )
204
+ {
205
+ _endDate = null ;
206
+ SetIsHighlightFalse ( _startCalendarDayButtons ) ;
207
+ return ;
208
+ }
178
209
if ( DateTime . TryParse ( _textBoxEnd . Text , out var dateTime ) )
179
210
{
180
211
if ( EndDate . HasValue && dateTime . ToString ( DateFormat ) == EndDate . Value . ToString ( DateFormat ) )
@@ -199,9 +230,20 @@ private void TextBoxEnd_TextChanged(object sender, TextChangedEventArgs e)
199
230
}
200
231
201
232
private void TextBoxStart_TextChanged ( object sender , TextChangedEventArgs e )
233
+ {
234
+ UpdateStartDateFromTextBox ( ) ;
235
+ }
236
+
237
+ void UpdateStartDateFromTextBox ( )
202
238
{
203
239
if ( _textBoxStart != null )
204
240
{
241
+ if ( string . IsNullOrWhiteSpace ( _textBoxStart . Text ) )
242
+ {
243
+ _startDate = null ;
244
+ SetIsHighlightFalse ( _startCalendarDayButtons ) ;
245
+ return ;
246
+ }
205
247
if ( DateTime . TryParse ( _textBoxStart . Text , out var dateTime ) )
206
248
{
207
249
if ( StartDate . HasValue && dateTime . ToString ( DateFormat ) == StartDate . Value . ToString ( DateFormat ) )
@@ -357,6 +399,8 @@ private void OnWindow_MouseDown(object sender, MouseButtonEventArgs e)
357
399
358
400
private void OnPreviewMouseUp ( object sender , MouseButtonEventArgs e )
359
401
{
402
+ if ( e . OriginalSource is Button button )
403
+ return ;
360
404
if ( _popup != null && ! _popup . IsOpen )
361
405
_popup . IsOpen = true ;
362
406
}
0 commit comments