Bug 42043 - Errors with DataTrigger and using CachingStrategy="RecycleElement"
Summary: Errors with DataTrigger and using CachingStrategy="RecycleElement"
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-06-21 18:27 UTC by Jon Goldberger [MSFT]
Modified: 2017-06-13 09:19 UTC (History)
9 users (show)

Tags: ac
Is this bug a regression?: ---
Last known good build:


Attachments
Test Project (217.48 KB, application/zip)
2016-06-21 18:27 UTC, Jon Goldberger [MSFT]
Details
Test Project using ViewModel instead of anonymous types. (217.58 KB, application/zip)
2016-06-21 18:32 UTC, Jon Goldberger [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Jon Goldberger [MSFT] 2016-06-21 18:27:40 UTC
Created attachment 16422 [details]
Test Project

## Description

When using CachingStrategy="RecycleElement" and DataTrigger,  the second label which uses a data trigger based on the value of the text property in the first label, after scrolling the second label shows the wrong value.

## Steps to reproduce

1. Launch the attached project, either Android or iOS.

2. Observe that the label in the second column has a formatted version of the number in the first column for items 1 through 15. items 16 and up, the first column is blank and the DataTrigger makes the second label read "not set". 

3. Scroll the list fully up and down a few times. 

Expected result: For items 1-15, the second column will always display a formatted version of the number in the first column.

Actual result: For items 1-15, the second column numbers are out of order, IOW you will have "1" in the first column and "15.00 m" in the second column for the first item in the list. 

## Notes

There seem to be several issue with using DataTriggers, but I am focusing on this issue for the bug report. 

Also note that if CachingStrategy="RecycleElement" is removed from DataTriggerDemoPage.xaml, this issue goes away (understandably). 

Issue occurs in XF 2.2 and 2.3.


## Environment

=== Xamarin Studio Enterprise ===

Version 6.0 (build 5174)
Installation UUID: ceaba76c-db06-4fbd-b326-f69ea53c3e01
Runtime:
	Mono 4.4.0 (mono-4.4.0-branch-c7-baseline/5995f74) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 404000182

=== Xamarin.Profiler ===

Not Installed

=== Xamarin.Android ===

Version: 6.1.0.71 (Visual Studio Enterprise)
Android SDK: /Users/jongoldberger/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
		5.0   (API level 21)
		5.1   (API level 22)
		6.0   (API level 23)

SDK Tools Version: 25.1.7
SDK Platform Tools Version: 23.1
SDK Build Tools Version: 23.0.3

Java SDK: /usr
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Android Player ===

Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

=== Xamarin Inspector ===

Version: 0.8.0.0
Hash: dc081aa
Branch: master
Build date: Tue Apr 26 23:07:44 UTC 2016

=== Apple Developer Tools ===

Xcode 7.3.1 (10188.1)
Build 7D1014

=== Xamarin.iOS ===

Version: 9.8.0.323 (Visual Studio Enterprise)
Hash: 39ebb77
Branch: cycle7
Build date: 2016-06-01 21:23:15-0400

=== Xamarin.Mac ===

Version: 2.8.0.323 (Visual Studio Enterprise)

=== Build Information ===

Release ID: 600005174
Git revision: 694a75f040b7f2309bc43d4f78a3a6572ca898bf
Build date: 2016-06-01 17:28:08-04
Xamarin addins: 33f406fa2dcf214012c78cb846585f062b2e1d24
Build lane: monodevelop-lion-cycle7-baseline

=== Operating System ===

Mac OS X 10.11.5
Darwin Jons-MacBook-Pro.local 15.5.0 Darwin Kernel Version 15.5.0
    Tue Apr 19 18:36:36 PDT 2016
    root:xnu-3248.50.21~8/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Xamarin Inspector 0.8.0.0
Comment 1 Jon Goldberger [MSFT] 2016-06-21 18:32:13 UTC
Created attachment 16423 [details]
Test Project using ViewModel instead of anonymous types.

Thinking that this issue _may_ be due to the use of anonymous types, I reworked the original test project to use a ViewModel. Results were the same.
Comment 3 Jon Goldberger [MSFT] 2016-06-21 19:00:59 UTC
Possibly related bug b#42044
Comment 4 Stephane Delcroix 2017-06-13 09:19:48 UTC
In this scenario (your use case slightly simplified):

  <Label Text="{Binding Value, StringFormat='{}{0:F2} m'}">
    <Label.Triggers>
      <DataTrigger TargetType="Label" Binding="{Binding Value}" Value="{x:Null}">
        <Setter Property="Text" Value="not set" />
      </DataTrigger>
    </Label.Triggers>
  </Label>

You have both the Binding and the DataTrigger competing for setting the Label.Text.
The value displayed is undetermined, and depends on which of the Binding or the Trigger sets the value last.
In addition, the Setter of the DataTrigger, when applied, will remove the Binding and if the cell is reused the Binding won't apply the next time.

We can not possibly support that kind of scenario. You should use a converter in your Binding instead of a DataTrigger.