Caliburn.Micro
Caliburn.Micro copied to clipboard
BindableCollection AddRange/RemoveRange NewItems/OldItems are now set
When adding objects to a BindableCollection the e.NewItems in the CollectionChanged event used to be empty.
Current version:
Fixed version:
Code snipped: Program.txt
Looks good, thanks, just need to do some legacy research. This is one of those changes that makes me wonder why it hasn't been done before.
be aware of dotnet/wpf#1887
Just in case it might be useful: some collections (such as ListCollectionView
) do not support ranged actions and throw. It works with Reset
.
I rebased my fork and updated the code
@Yinimi Code looks good. Need to do some testing this weekend
@KasperSK it is testing out ok. What do you think about merging it in?
@vb2ae Could we test the case mentioned in dotnet/wpf#1887? Seems bad if we could get runtime exceptions when running WPF.
Tested with this code
protected override async Task OnActivateAsync(CancellationToken cancellationToken)
{
Numbers = new BindableCollection<int>();
Numbers.CollectionChanged += Numbers_CollectionChanged;
for (int x = 0; x < 10000; x++)
{
Numbers.Add(x);
}
}
public void btnChangeCollection()
{
Random rnd = new Random();
var lst = new List<int>();
for (int x = 0; x < 100; x++)
{
lst.Add(Numbers[x]);
}
Numbers.RemoveRange(lst);
var lstToAdd = new List<int>();
for (int z = 0; z < 100; z++)
{
lstToAdd.Add(rnd.Next(200000));
}
Numbers.AddRange(lstToAdd);
}
Numbers was bound to a listbox. AddRange and RemoveRange throw exceptions like @tibel mentioned
Looks like we should not merge this before WPF has fixed the issue then.