@@ -214,25 +214,22 @@ public override void OnApplyTemplate()
214
214
215
215
private void TextBoxOnLostFocus ( object sender , RoutedEventArgs routedEventArgs )
216
216
{
217
- if ( _textBox == null ) return ;
217
+ if ( string . IsNullOrEmpty ( _textBox ? . Text ) ) return ;
218
218
219
- if ( ! string . IsNullOrEmpty ( _textBox . Text ) )
220
- {
221
- DateTime time ;
222
- if ( IsTimeValid ( _textBox . Text , out time ) )
223
- SetCurrentValue ( SelectedTimeProperty , time ) ;
219
+ DateTime time ;
220
+ if ( IsTimeValid ( _textBox . Text , out time ) )
221
+ SetCurrentValue ( SelectedTimeProperty , time ) ;
224
222
225
- else // Invalid time, jump back to previous good time
226
- SetInvalidTime ( ) ;
227
- }
228
- }
223
+ else // Invalid time, jump back to previous good time
224
+ SetInvalidTime ( ) ;
225
+ }
229
226
230
227
private void SetInvalidTime ( )
231
228
{
232
229
if ( _lastValidTime != null )
233
230
{
234
- SetCurrentValue ( SelectedTimeProperty , ( DateTime ) _lastValidTime ) ;
235
- _textBox . Text = SelectedTime . Value . ToString ( SelectedTime . Value . Hour % 12 > 9 ? "hh:mm tt" : "h:mm tt" ) ;
231
+ SetCurrentValue ( SelectedTimeProperty , _lastValidTime . Value ) ;
232
+ _textBox . Text = _lastValidTime . Value . ToString ( _lastValidTime . Value . Hour % 12 > 9 ? "hh:mm tt" : "h:mm tt" ) ;
236
233
}
237
234
238
235
else
@@ -289,9 +286,7 @@ private void TextBoxOnTextChanged(object sender, TextChangedEventArgs textChange
289
286
290
287
private void SetSelectedTime ( )
291
288
{
292
- if ( _textBox == null ) return ;
293
-
294
- if ( ! string . IsNullOrEmpty ( _textBox . Text ) )
289
+ if ( ! string . IsNullOrEmpty ( _textBox ? . Text ) )
295
290
{
296
291
ParseTime ( _textBox . Text , t => SetCurrentValue ( SelectedTimeProperty , t ) ) ;
297
292
}
@@ -306,7 +301,7 @@ private void ParseTime(string s, Action<DateTime> successContinuation)
306
301
successContinuation ( time ) ;
307
302
}
308
303
309
- private bool IsTimeValid ( string s , out DateTime time )
304
+ private static bool IsTimeValid ( string s , out DateTime time )
310
305
{
311
306
return DateTime . TryParse ( s ,
312
307
CultureInfo . CurrentCulture ,
@@ -339,9 +334,7 @@ private void PopupOnPreviewMouseLeftButtonDown(object sender, MouseButtonEventAr
339
334
var popup = sender as Popup ;
340
335
if ( popup == null || popup . StaysOpen ) return ;
341
336
342
- if ( _dropDownButton == null ) return ;
343
-
344
- if ( _dropDownButton . InputHitTest ( mouseButtonEventArgs . GetPosition ( _dropDownButton ) ) != null )
337
+ if ( _dropDownButton ? . InputHitTest ( mouseButtonEventArgs . GetPosition ( _dropDownButton ) ) != null )
345
338
{
346
339
// This popup is being closed by a mouse press on the drop down button
347
340
// The following mouse release will cause the closed popup to immediately reopen.
0 commit comments