Fixes IObservableVector based ItemsSource exception
Fixes #4263 and #2913
PR Type
What kind of change does this PR introduce?
Bugfix
What is the current behavior?
What is the new behavior?
PR Checklist
Please check if your PR fulfills the following requirements:
- [ ] Tested code with current supported SDKs
- [ ] New component
- [ ] Pull Request has been submitted to the documentation repository instructions. Link:
- [ ] Added description of major feature to project description for NuGet package (4000 total character limit, so don't push entire description over that)
- [ ] If control, added to Visual Studio Design project
- [ ] Sample in sample app has been added / updated (for bug fixes / features)
- [ ] Icon has been created (if new sample) following the Thumbnail Style Guide and templates
- [ ] New major technical changes in the toolkit have or will be added to the Wiki e.g. build changes, source generators, testing infrastructure, sample creation changes, etc...
- [x] Tests for the changes have been added (for bug fixes / features) (if applicable)
- [ ] Header has been added to all new source files (run build/UpdateHeaders.bat)
- [x] Contains NO breaking changes
Other information
Thanks w-libs for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌
This PR has been marked as "needs attention 👋" and awaiting a response from the team.
@Arlodotexe this should be a good quick one to review too. Let me know your thoughts.
Hi guys,
When you plan apply this fix ?
DataGrid is unusable when you use CollectionViewSource and would like to manipulate data which are bounded under the hood.
My case:
Items has for ex. 10 elements.
ObservableCollection<Item> items = GetItems();
CollectionViewSource source = new CollectionViewSource
{
IsSourceGrouped = false,
Source = items
};
DataGrid.ItemsSource = source.View;
I am removing items in that way:
private void RemoveItem(Item itemToRemove)
{
if (source is ObservableCollection<Item> items)
{
if (items.Contains(itemToRemove)
{
items.Remove(itemToRemove);
}
}
}
or
private void RemoveItem(Item itemToRemove)
{
if (source.View.Contains(itemToRemove)
{
source.View.Remove(itemToRemove);
}
}
When I will try to remove random item but not the last one - everything is ok.
When I will try to remove the last one - System.ArgumentOutOfRangeException happens.
Is there a chance to put the fix to the next release ? The fix waiting for merge over almost 1.5 years.