Skip to content

Commit

Permalink
fixed NullReferenceException in FileSystemControl
Browse files Browse the repository at this point in the history
  • Loading branch information
spiegelp committed Mar 21, 2021
1 parent 79fe44b commit 0a6acb0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
20 changes: 16 additions & 4 deletions MaterialDesignExtensions/Controls/FileSystemControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,11 @@ public override void OnApplyTemplate()
protected virtual void LoadedHandler(object sender, RoutedEventArgs args)
{
m_controller.PropertyChanged += ControllerPropertyChangedHandler;
m_currentDirectoryTextBox.KeyDown += CurrentDirectoryTextBoxKeyDownHandler;

if (m_currentDirectoryTextBox != null)
{
m_currentDirectoryTextBox.KeyDown += CurrentDirectoryTextBoxKeyDownHandler;
}

// not sure if the control should get keyboard focus on loading
//Keyboard.Focus(this);
Expand All @@ -408,7 +412,11 @@ protected virtual void LoadedHandler(object sender, RoutedEventArgs args)
protected virtual void UnloadedHandler(object sender, RoutedEventArgs args)
{
m_controller.PropertyChanged -= ControllerPropertyChangedHandler;
m_currentDirectoryTextBox.KeyDown -= CurrentDirectoryTextBoxKeyDownHandler;

if (m_currentDirectoryTextBox != null)
{
m_currentDirectoryTextBox.KeyDown -= CurrentDirectoryTextBoxKeyDownHandler;
}
}

protected void OpenSpecialDirectoriesDrawerCommandHandler(object sender, ExecutedRoutedEventArgs args)
Expand All @@ -424,7 +432,7 @@ protected void SwitchPathPartsAsButtonsHandler(object sender, ExecutedRoutedEven

private void CurrentDirectoryTextBoxKeyDownHandler(object sender, KeyEventArgs args)
{
if (args.Key == Key.Enter)
if (sender == m_currentDirectoryTextBox && args.Key == Key.Enter)
{
string directory = m_currentDirectoryTextBox.Text
.Replace("\n", string.Empty)
Expand Down Expand Up @@ -541,7 +549,11 @@ protected virtual void CurrentDirectoryChangedHandler(string newCurrentDirectory
try
{
m_controller.SelectDirectory(newCurrentDirectory);
m_currentDirectoryTextBox.Text = newCurrentDirectory;

if (m_currentDirectoryTextBox != null)
{
m_currentDirectoryTextBox.Text = newCurrentDirectory;
}
}
catch (PathTooLongException)
{
Expand Down
1 change: 1 addition & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,4 @@ Please change your configuration according to [App.xaml](https://github.com/spie
#### Fixes
* Fixed reflection code in `ResourceDictionaryExtensions`
* Fixed usage of `SecondaryHueMidBrush` and `SecondaryHueMidForegroundBrush` resources
* Fixed `NullReferenceException` in `FileSystemControl`
3 changes: 2 additions & 1 deletion docs/snippets/releasenotes.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ <h3>Features</h3>
<h3>Fixes</h3>
<ul>
<li>Fixed reflection code in <code>ResourceDictionaryExtensions</code></li>
<li>Fixed usage of <code>SecondaryHueMidBrush</code> and <code>SecondaryHueMidForegroundBrush</code> resources</li>
<li>Fixed <code>NullReferenceException</code> in <code>FileSystemControl</code></li>
</ul>
<h2>v3.2.0</h2>
<h3>Features</h3>
Expand All @@ -54,7 +56,6 @@ <h3>Features</h3>
<h3>Fixes</h3>
<ul>
<li>Fixed exception in <code>Stepper</code> events</li>
<li>Fixed usage of <code>SecondaryHueMidBrush</code> and <code>SecondaryHueMidForegroundBrush</code> resources</li>
</ul>
<h2>v3.1.0</h2>
<h3>Features</h3>
Expand Down

0 comments on commit 0a6acb0

Please sign in to comment.