Fix crash when trying to filter an empty PropertyGrid

This commit is contained in:
Brant Martin
2018-04-27 10:26:17 -04:00
parent b9e9be227a
commit 7404b6bd2d
2 changed files with 5 additions and 1 deletions

View File

@@ -17,7 +17,7 @@
<ColumnDefinition/> <ColumnDefinition/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="Filter: " Margin="3"/> <TextBlock Grid.Column="0" Text="Filter: " Margin="3"/>
<TextBox Grid.Column="1" Margin="3" TextChanged="UpdateFilter"/> <TextBox Name="TbFilter" Grid.Column="1" Margin="3" TextChanged="UpdateFilter" IsEnabled="False"/>
</Grid> </Grid>
<ScrollViewer Grid.Row="1" x:Name="ScrollViewer"/> <ScrollViewer Grid.Row="1" x:Name="ScrollViewer"/>
<TextBlock x:Name="TbDescription" Grid.Row="2" MinHeight="18"/> <TextBlock x:Name="TbDescription" Grid.Row="2" MinHeight="18"/>

View File

@@ -49,12 +49,14 @@ namespace Torch.Views
if (e.NewValue == null) if (e.NewValue == null)
{ {
ScrollViewer.Content = null; ScrollViewer.Content = null;
TbFilter.IsEnabled = false;
return; return;
} }
var content = GenerateForType(e.NewValue.GetType()); var content = GenerateForType(e.NewValue.GetType());
content.DataContext = e.NewValue; content.DataContext = e.NewValue;
ScrollViewer.Content = content; ScrollViewer.Content = content;
TbFilter.IsEnabled = true;
} }
public Grid GenerateForType(Type t) public Grid GenerateForType(Type t)
@@ -274,6 +276,8 @@ namespace Torch.Views
{ {
var filterText = ((TextBox)sender).Text; var filterText = ((TextBox)sender).Text;
var grid = (Grid)ScrollViewer.Content; var grid = (Grid)ScrollViewer.Content;
if (grid == null)
return;
foreach (var child in grid.Children) foreach (var child in grid.Children)
{ {
if (!(child is TextBlock block)) if (!(child is TextBlock block))