I have an observabelCollection of a data object:
public ObservableCollection<GistViewModel> Gists { get => gists; set => SetProperty(ref gists, value); }
Each GistViewModel
has the following:
public BindingList<GistFileViewModel> GistFiles { get => gistFiles; }
In terms of what this represents, each Gist has a collection of GistFiles. I am mapping this onto a TreeViewControl (root being Gists, Child being GistFiles) via the following xaml (abridged):
<!-- GistLevel -->
<HierarchicalDataTemplate DataType="{x:Type viewmodels:GistViewModel}" ItemsSource="{Binding Path=GistsFiles}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding GistFiles, Converter={StaticResource GistFilesToFirstFilenameConverter}}"></TextBlock>
</StackPanel>
</HierarchicalDataTemplate>
<!-- GIST FILE LEVEL -->
<DataTemplate DataType="{x:Type viewmodels:GistFileViewModel}">
<StackPanel Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" Margin="2,0,2,0" Text="{Binding Filename}"></TextBlock>
</StackPanel>
</DataTemplate>
<TreeView x:Name="GistsTV" ItemsSource="{Binding Gists}"/>
This works successfully. Now I am trying to introduce a filter feature. I have followed a guide online somewhere which advises using ICollectionView
. I implement this thus:
public ICollectionView GistsView { get => CollectionViewSource.GetDefaultView(Gists); }
private async Task GetAllGistsAsync()
{
Gists = await gistManager.LoadGistsAsync();
GistsView.Refresh();
}
And changing my xaml to:
<TreeView x:Name="GistsTV" ItemsSource="{Binding GistsView}"/>
I’m just trying to get the default list presented first. However, this does not work. No list items are displayed.
GistFilesToFirstFilenameConverter
doesn’t get called when Binding = GistsView
The full code is here: https://github.com/stigzler/VisGist/blob/master/VisGist/ToolWindows/MainWindow.xaml
What am I missing?