I've these collection and collectionviews:
public ICollectionView Tenants { get; set; }
public ICollectionView Plots { get; set; }
List<int> foundPlots
and these subscription and filters:
Tenants.CurrentChanged += onTenantChanged;
Plots.CurrentChanged += onPlotChanged;
Plots.Filter = filterPlots;
I don't want to have duplicates in Plots
so to keep track of plot that has passed the filter, I add PlotId
of the lease in foundPlots
. Whenever onTenantChanged
is called, I clear the foundPlots
:
void onTenantChanged(object sender, EventArgs e)
{
foundPlots.Clear();
selectedTenant = Tenants.CurrentItem as Tenant;
Plots.Refresh();
Plots.MoveCurrentToFirst();
}
and it resets the selectedPlot
:
void onPlotChanged(object sender, EventArgs e)
{
selectedPlot = Plots.CurrentItem as Lease;
...
}
and in filterPlots
method I've these:
bool filterPlots(object o)
{
if (selectedTenant == null) return false;
var lease = (o as Lease);
if(selectedTenant.Id == lease.TenantId)
{
var contained = foundPlots.Contains(lease.PlotId);
if (!contained) foundPlots.Add(lease.PlotId);
return !contained;
}
return false;
}
It works if I add a Lease
object in the underlying collection Plots
is pointing to and also works if I don't modify the underlying collection. If I, however, replace a lease or after modifying a property of a Lease
in the collection, call RaiseCollectionChanged()
on the underlying collection, filterPlots
is invoked and it doesn't get the chance to clear the foundPlots
and I get unexpected results!
Is there a way to access the internal filtered collection of Plots
in filterPlots
method to check which plots have passed the filter already as the filter progresses?