-
Notifications
You must be signed in to change notification settings - Fork 1.9k
CollectionView with EmptyView and EmptyViewTemplate for Data template selector throws an exception #25418
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
Conversation
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
/rebase |
5f86a88 to
c20e876
Compare
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
/rebase |
c20e876 to
e8c0a38
Compare
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
jsuarezruiz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
/rebase |
de94bea to
d95cb8d
Compare
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
| { | ||
| // Is view set on the ItemsView? | ||
| if (view is null && viewTemplate is null) | ||
| if (view is null && (viewTemplate is null || viewTemplate is DataTemplateSelector)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the PR description:
"The exception occurred because the RealizeView method in the ItemsViewController file was attempting to create and render a view when both EmptyView and EmptyViewTemplate were defined in the CollectionView, with a DataTemplateSelector for the EmptyViewTemplate. The original code did not account for the scenario where the viewTemplate was a DataTemplateSelector."
In the case of using a DataTemplateSelector, here
| viewTemplate = viewTemplate.SelectDataTemplate(view, itemsView); |
should select the correct template, and then get the content to create the handler and the PlatformView.
Is the SelectTemplate method returning null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsuarezruiz ,
In this case, the SelectTemplate method itself isn't returning null. Instead, the exception occurs immediately afterward, when the selected viewTemplate is used in CreateContent. This happens because, on the initial render, there's no template available to select, resulting in viewTemplate being null. This leads to an exception when CreateContent is called with an empty or unassigned DataTemplateSelector.
Let me know if further clarification is needed!
10bf138 to
d701ce3
Compare
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Changes Addressed

Root Cause
The exception occurred because the
RealizeViewmethod in theItemsViewControllerfile was attempting to create and render a view when bothEmptyViewandEmptyViewTemplatewere defined in theCollectionView, with aDataTemplateSelectorfor theEmptyViewTemplate. The original code did not account for the scenario where theviewTemplatewas aDataTemplateSelector. In this case, theRealizeViewmethod expected aDataTemplateto be directly provided, leading to anullreference issue when trying to use theviewTemplate. This caused an exception when it encountered aDataTemplateSelector, which should dynamically choose the correct template based on the input data.Description of Change
The fix introduced an additional condition to handle cases where the
viewTemplateis aDataTemplateSelector. This ensures that when theviewis null and theviewTemplateis either null or aDataTemplateSelector, the logic correctly bypasses attempting to realize a non-existent view. This fix code prevents the exception by ensuring that the method can handleDataTemplateSelectorcases, avoiding invalid template realization, and allowing theCollectionViewto display the appropriate empty view template without errors.Tested the behaviour in the following platforms
Issues Fixed
Fixes #25224
Screenshots
iOS:
Mac: