@@ -214,25 +214,22 @@ public override void OnApplyTemplate()
214214
215215 private void TextBoxOnLostFocus ( object sender , RoutedEventArgs routedEventArgs )
216216 {
217- if ( _textBox == null ) return ;
217+ if ( string . IsNullOrEmpty ( _textBox ? . Text ) ) return ;
218218
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 ) ;
224222
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+ }
229226
230227 private void SetInvalidTime ( )
231228 {
232229 if ( _lastValidTime != null )
233230 {
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" ) ;
236233 }
237234
238235 else
@@ -289,9 +286,7 @@ private void TextBoxOnTextChanged(object sender, TextChangedEventArgs textChange
289286
290287 private void SetSelectedTime ( )
291288 {
292- if ( _textBox == null ) return ;
293-
294- if ( ! string . IsNullOrEmpty ( _textBox . Text ) )
289+ if ( ! string . IsNullOrEmpty ( _textBox ? . Text ) )
295290 {
296291 ParseTime ( _textBox . Text , t => SetCurrentValue ( SelectedTimeProperty , t ) ) ;
297292 }
@@ -306,7 +301,7 @@ private void ParseTime(string s, Action<DateTime> successContinuation)
306301 successContinuation ( time ) ;
307302 }
308303
309- private bool IsTimeValid ( string s , out DateTime time )
304+ private static bool IsTimeValid ( string s , out DateTime time )
310305 {
311306 return DateTime . TryParse ( s ,
312307 CultureInfo . CurrentCulture ,
@@ -339,9 +334,7 @@ private void PopupOnPreviewMouseLeftButtonDown(object sender, MouseButtonEventAr
339334 var popup = sender as Popup ;
340335 if ( popup == null || popup . StaysOpen ) return ;
341336
342- if ( _dropDownButton == null ) return ;
343-
344- if ( _dropDownButton . InputHitTest ( mouseButtonEventArgs . GetPosition ( _dropDownButton ) ) != null )
337+ if ( _dropDownButton ? . InputHitTest ( mouseButtonEventArgs . GetPosition ( _dropDownButton ) ) != null )
345338 {
346339 // This popup is being closed by a mouse press on the drop down button
347340 // The following mouse release will cause the closed popup to immediately reopen.
0 commit comments