Skip to content

Commit 0a6acb0

Browse files
committed
fixed NullReferenceException in FileSystemControl
1 parent 79fe44b commit 0a6acb0

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

MaterialDesignExtensions/Controls/FileSystemControl.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
{

ReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,4 @@ Please change your configuration according to [App.xaml](https://github.com/spie
197197
#### Fixes
198198
* Fixed reflection code in `ResourceDictionaryExtensions`
199199
* Fixed usage of `SecondaryHueMidBrush` and `SecondaryHueMidForegroundBrush` resources
200+
* Fixed `NullReferenceException` in `FileSystemControl`

docs/snippets/releasenotes.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ <h3>Features</h3>
3232
<h3>Fixes</h3>
3333
<ul>
3434
<li>Fixed reflection code in <code>ResourceDictionaryExtensions</code></li>
35+
<li>Fixed usage of <code>SecondaryHueMidBrush</code> and <code>SecondaryHueMidForegroundBrush</code> resources</li>
36+
<li>Fixed <code>NullReferenceException</code> in <code>FileSystemControl</code></li>
3537
</ul>
3638
<h2>v3.2.0</h2>
3739
<h3>Features</h3>
@@ -54,7 +56,6 @@ <h3>Features</h3>
5456
<h3>Fixes</h3>
5557
<ul>
5658
<li>Fixed exception in <code>Stepper</code> events</li>
57-
<li>Fixed usage of <code>SecondaryHueMidBrush</code> and <code>SecondaryHueMidForegroundBrush</code> resources</li>
5859
</ul>
5960
<h2>v3.1.0</h2>
6061
<h3>Features</h3>

0 commit comments

Comments
 (0)