xamarin/Xamarin.Forms

Retain Strategy on Listview with DataTemplateSelector causes BindingContext to revert to null

开放

#3,602 创建于 2018年8月17日

 (0 条评论) (0 个反应) (0 位负责人)C# (1,926 个派生)batch import
a/listviewe/4 :clock4:help wantedinactivet/bug :bug:up-for-grabs

仓库指标

星标
 (5,644 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

Description

The issue seems to come up because of this await

https://github.com/xamarin/Xamarin.Forms/blob/a9a7277ad8d6b40a9f28081c248ba282a6476d95/Xamarin.Forms.Core/TemplatedItemsList.cs#L1206

The await happens, a new template is swapped in, and then the above code sets the BindingContext back to null. If you set the ListView Cache strategy to Recycle the issue doesn't happen because that await doesn't occur

For example I had to do this little hack here

https://github.com/xamarin/Xamarin.Forms/pull/3518/files#diff-bb6d28847711cc5f78841d28a70d000bR168

To make sure the BindingContext doesn't get reset back to null after already being set inside the DataTemplateSelector

Steps to Reproduce

In the Control Gallery remove the hack I added above and you'll see the effect of the BindingContext getting set and then unset to null because of the race condition

Expected Behavior

The BindingContext on the view cell should remain what I set it to. A pending operation shouldn't set it back to null.

Actual Behavior

A pending operation sets the BindingContext back to null

Basic Information

  • Version with issue: 3.2
  • Last known good version: Not sure

贡献者指南