[UWP] Issue2927 failing and Tapped is passing the wrong value in for Item
#5,465 opened on Mar 6, 2019
Repository metrics
- Stars
- (5,644 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
Description
This is a little tricky to explain or I just confused myself while working on this
https://github.com/xamarin/Xamarin.Forms/pull/3400
Appears to have fixed https://github.com/xamarin/Xamarin.Forms/issues/4901 because it made it so that two (maybe more) wrongs made a right
If you run Issue2927 on master it will crash because PR https://github.com/xamarin/Xamarin.Forms/pull/3400 made it so the BindingContext gets passed into the ItemTapped event args but what should be passed into ItemTapped is the View not the BindingContext
The reason this seems to have worked is that there is a bug on UWP where if the BindingContext implements a Cell then the BindingContext is used as the template rather than the template. Issue 935 masks this behavior because the ItemSource is using the same class (that inherits from Cell) as the template.
If you run Issue 935 with pre PR 3400 changes the Tapped event does in fact fire. The problem is that it's firing against the incorrectly renderered Cell Control so the changes don't take effect on the view.
From what I can tell this happens because the CellControl on UWP doesn't use the TemplatedItems list to create controls it just goes right the template on the list View
Where as the other platforms go via the TemplatedItems List https://github.com/xamarin/Xamarin.Forms/blob/4cfa82569dd74858849eff6bd30cdf1b6ce7552c/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs#L539
I have a branch I've started working on over here https://github.com/xamarin/Xamarin.Forms/tree/fix_uwp_cell
Some of the ideas are rough and I don't think it works with grouping or TableViews yet But it does fix the issues presented by Issue2927 and Issue 935
Another fun way to see this on UWP is to just set the DataSource to various ViewCell types
var items = new ViewCell [] {
new CustomViewCell(),
new SomeOtherViewCell()
};
var cellTemplate = new DataTemplate (typeof(CustomViewCell));
var list = new ListView () {
ItemTemplate = cellTemplate,
ItemsSource = items
};
It will just render whatever the BindingContext is for that particular row totally ignoring the DataTemplate. Which is kind of a fun hack :-) though not intentional
Steps to Reproduce
Issue2927 crashes if you fix the crash on Issue2927 the make sure Issue 935 still works
Expected Behavior
Issue 935 and Issue2927 should be able to simultaneously work
Actual Behavior
they don't