Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AdvancedCollectionView: Exception thrown in ItemOnPropertyChanged when live shaping enabled but no filter set #1686

Closed
TheShihan opened this issue Dec 6, 2017 · 3 comments
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior helpers ✋ in progress 🚧
Milestone

Comments

@TheShihan
Copy link

I'm submitting a...

[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report  <!-- Please search GitHub for a similar issue or PR before submitting -->
[ ] Feature request <!-- Please file a UserVoice request and include the link below https://wpdev.uservoice.com/forums/110705-universal-windows-platform/category/193402-uwp-community-toolkit -->
[ ] Sample app request
[ ] Documentation issue or request
[ ] Question of Support request => Please do not submit support request here, instead see https://github.com/Microsoft/UWPCommunityToolkit/blob/master/contributing.md#question

Current behavior

I'm using an AdvancedCollectionView bound to a ListView to display items sorted by a DateTime property. I noticed that an exception occured in the OnPropertyChanged of the bound items when live shaping was enabled (true passed as second parameter to AdvancedViewCollection). After further analysis I saw that the NullReferenceException was thrown inside method ItemOnPropertyChanged of AdvancedCollectionView. This line throws the Exception when no filter has been set:
var filterResult = _filter(item);
So I changed my setup of the AVC from:

                    _acv = new AdvancedCollectionView(_timeEntries, true);
                    _acv.SortDescriptions.Add(new SortDescription("DateAndTime", SortDirection.Ascending));

to the following:

                    _acv = new AdvancedCollectionView(_timeEntries, true);
                    _acv.Filter = te => !string.IsNullOrWhiteSpace(((TimeEntry)te).Title);
                    _acv.SortDescriptions.Add(new SortDescription("DateAndTime", SortDirection.Ascending));

I added a dummy filter, that filters out items without a title (which never occurs anyway), just so that I don't run into the NullReferenceException.

Expected behavior

Live Shaping should work without a filter set.

Minimal reproduction of the problem with instructions

Initialise an AVC with live shaping enabled, don't setup a filter
AVC should consume an ObserverableCollection and bind the AVC to the ItemSource of a ListView.
Make sure the items of the collection implement INotifyPropertyChanged and you fire an event for property changes. Make use of the properties inside the ListView (data template). Edit a property to make the event fire. Exception should occur when OnPropertyChanged fires.

Environment

Nuget Package(s): 
- Microsoft.NETCore.UniversalWindowsPlatform

Package Version(s): 
- Microsoft.NETCore.UniversalWindowsPlatform 6.0.4

Windows 10 Build Number:
- [ ] Anniversary Update (14393) 
- [ ] Creators Update (15063)
- [ X] Fall Creators Update (16299)
- [ ] Insider Build (xxxxx)

App min and target version:
- [ X] Anniversary Update (14393) 
- [ ] Creators Update (15063)
- [ X] Fall Creators Update (16299)
- [ ] Insider Build (xxxxx)

Device form factor:
- [X] Desktop
- [ ] Mobile
- [ ] Xbox
- [ ] Surface Hub
- [ ] IoT

Visual Studio 
- [ ] 2017 15.3
- [X] 2017 15.4

@nmetulev
Copy link
Contributor

nmetulev commented Dec 7, 2017

@Shayon, any thoughts on this?

@nmetulev nmetulev added bug 🐛 An unexpected issue that highlights incorrect behavior helpers ✋ labels Dec 7, 2017
@Shayon
Copy link
Contributor

Shayon commented Dec 7, 2017

I think I see the issue. Looks like I missed this. 😞 I'll look into adding a test and fixing the functionality.

For now the workaround identified by @TheShihan will fix this issue. i.e. Adding a dummy filter like: _acv.Filter = x => true; when live shaping is enabled.

@nmetulev nmetulev added this to the v2.2 milestone Dec 7, 2017
@TheShihan TheShihan changed the title AdvancedCollectionView: Exception thrown in ItemOnPropertyChanged when live shaping enable but no filter set AdvancedCollectionView: Exception thrown in ItemOnPropertyChanged when live shaping enabled but no filter set Dec 7, 2017
@skendrot
Copy link
Contributor

Merged in #1688

@ghost ghost locked as resolved and limited conversation to collaborators Nov 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior helpers ✋ in progress 🚧
Projects
None yet
Development

No branches or pull requests

4 participants