I have some sort of cascaded containers that contain notes, where there is one master container, that contains all notes. The notes containers are made in a tree like hierarchy that get more specific the deeper you are in tree-structure. The reason why I have only one list has to do with a very complex house keeping of the data and it's not part of the problem.
The master note container has an ObservableCollection and all sub notes containers are bound to the ObservableCollection via CollectionView. The sub notes containers have a filter that filter out their notes. In regular code everything works fine and the view always shows the elements, but when I bind them to a e. g. ListBox, the elements are not filtered and all elements from the master list are shown without filtering. Of course I know there is a ListCollectionView, but since CollectionView is from IEnumerable, I'm curious how the ListBox has access to the master list, if it does not access the SourceCollection from the CollectionView.
In other words, I'm not quite sure why I need the ListCollectionView for very basic behaviour where the ColletionView should fit. It seems to me that the ListCollectionView is mandatory and not other view really fits to the ListBox?
Here is a small sample
XAML:
<Window x:Class="ListCollection.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<StackPanel Orientation="Horizontal">
<ListBox Width="100" ItemsSource="{Binding Model}"></ListBox>
<ListBox Width="100" ItemsSource="{Binding View1}"></ListBox>
<ListBox Width="100" ItemsSource="{Binding View2}"></ListBox>
</StackPanel>
</Window>
C#:
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using System.Windows.Data;
namespace ListCollection
{
/// <summary>
/// Interaktionslogik für MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public ObservableCollection<int> Model
{
get;
private set;
}
public ICollectionView View1
{
get;
private set;
}
public ICollectionView View2
{
get;
private set;
}
public MainWindow()
{
InitializeComponent();
DataContext = this;
Model = new ObservableCollection<int>();
View1 = new CollectionView(Model);
View1.Filter = (o) =>
{
return ((int)o) > 50;
};
View2 = new CollectionView(View1);
View2.Filter = (o) =>
{
return ((int)o) > 70;
};
for (int i = 0; i < 100; i++)
Model.Add(i);
}
}
}
Thanks Martin