Open yairp03 opened 2 years ago
I suggest adding area/collectionView
tag
We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.
If we want to use
or , we can't use compiled binding on the page, because then it will require us to specify the x:DataType for the DataTemplate, which we can't do.
I think this should be in the official Documentation as a warning.
Maybe someone else would've realized sooner than me but I spent a long time today thinking I was doing something wrong because of this. I resorted to not using
Description
This feature determines automatically the
DataType
of aDataTemplate
inside<CollectionView.ItemTemplate>
,<CollectionView.GroupHeaderTemplate>
and/or<CollectionView.GroupFooterTemplate>
, without need of specifyingx:DataType
manually. Also, it allows using anx:DataType
on a page when there is Group Header/Footer Template that using group attributes.Normal CollectionView
For example, I have this
Monkey
model:Inside the ViewModel, I have this list of monkeys:
And in the page, I have a
CollectionView
with a binding to theMonkeysList
:Currently, in order to use the
ItemTemplate
without getting any binding error, I need to specify the type of the item usingx:DataType
on theDataTemplate
tag, like this:Feature benefits
This feature will make the code cleaner, will enable doing the same thing without specifying the
x:DataType
, and will automatically determine that because theCollectionView
'sItemSource
is a Collection ofMonkey
's, then each item is aMonkey
.Grouped CollectionView
In a grouped
CollectionView
, theItemSource
needs to be anIEnumerable
ofIEnumerable
s. For example:If we want to use
<CollectionView.GroupHeaderTemplate>
or<CollectionView.GroupFooterTemplate>
, we can't use compiled binding on the page, because then it will require us to specify thex:DataType
for theDataTemplate
, which we can't do. For example:Feature benefits
Besides the code being cleaner, this feature will allow using compiled binding on a page that has a grouped
CollectionView
in it, that uses the group's header and/or footer templates.Final code with the feature
Public API Changes
Code
The example will use this code:
Normal CollectionView
For a non-grouped
CollectionView
, the xaml code, instead of this:Will look like this:
Grouped CollectionView
For a grouped
CollectionView
, the xaml code, instead of this:Will look like this:
Intended Use-Case
The feature will be used on any page that has a
CollectionView
in it and will make the code cleaner. Also, it will enable to use compiled bindings on the page, even if it has a groupedCollectionView
that uses group members inside the group header and/or footer templates.