@@ -399,7 +399,11 @@ public override void OnApplyTemplate()
399399 protected virtual void LoadedHandler ( object sender , RoutedEventArgs args )
400400 {
401401 m_controller . PropertyChanged += ControllerPropertyChangedHandler ;
402- m_currentDirectoryTextBox . KeyDown += CurrentDirectoryTextBoxKeyDownHandler ;
402+
403+ if ( m_currentDirectoryTextBox != null )
404+ {
405+ m_currentDirectoryTextBox . KeyDown += CurrentDirectoryTextBoxKeyDownHandler ;
406+ }
403407
404408 // not sure if the control should get keyboard focus on loading
405409 //Keyboard.Focus(this);
@@ -408,7 +412,11 @@ protected virtual void LoadedHandler(object sender, RoutedEventArgs args)
408412 protected virtual void UnloadedHandler ( object sender , RoutedEventArgs args )
409413 {
410414 m_controller . PropertyChanged -= ControllerPropertyChangedHandler ;
411- m_currentDirectoryTextBox . KeyDown -= CurrentDirectoryTextBoxKeyDownHandler ;
415+
416+ if ( m_currentDirectoryTextBox != null )
417+ {
418+ m_currentDirectoryTextBox . KeyDown -= CurrentDirectoryTextBoxKeyDownHandler ;
419+ }
412420 }
413421
414422 protected void OpenSpecialDirectoriesDrawerCommandHandler ( object sender , ExecutedRoutedEventArgs args )
@@ -424,7 +432,7 @@ protected void SwitchPathPartsAsButtonsHandler(object sender, ExecutedRoutedEven
424432
425433 private void CurrentDirectoryTextBoxKeyDownHandler ( object sender , KeyEventArgs args )
426434 {
427- if ( args . Key == Key . Enter )
435+ if ( sender == m_currentDirectoryTextBox && args . Key == Key . Enter )
428436 {
429437 string directory = m_currentDirectoryTextBox . Text
430438 . Replace ( "\n " , string . Empty )
@@ -541,7 +549,11 @@ protected virtual void CurrentDirectoryChangedHandler(string newCurrentDirectory
541549 try
542550 {
543551 m_controller . SelectDirectory ( newCurrentDirectory ) ;
544- m_currentDirectoryTextBox . Text = newCurrentDirectory ;
552+
553+ if ( m_currentDirectoryTextBox != null )
554+ {
555+ m_currentDirectoryTextBox . Text = newCurrentDirectory ;
556+ }
545557 }
546558 catch ( PathTooLongException )
547559 {
0 commit comments