Bug 42044 - DataTrigger not working correctly.
Summary: DataTrigger not working correctly.
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:58 UTC by Jon Goldberger [MSFT]
Modified: 2017-06-14 09:05 UTC (History)
12 users (show)

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


Attachments
Test Project (223.27 KB, application/zip)
2016-06-21 18:58 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:58:02 UTC
Created attachment 16426 [details]
Test Project

## Description

DataTrigger does not seem to be working correctly. The DataTrigger does not always set the correct value. I see this issue always on iOS but occasionally on Android as well. 

## Steps to reproduce:

1. Launch the attached test project to an iOS device or simulator. 

2. View the list.

Expected result: Items 16-30, which have no value for the first column, should have "not set" in the second column.

Actual result: Some of the 16-30 items have "m" in the second column.

## Notes

Basically items 1-15 should show a simple number ("1"-"15") in the 1st column and a formatted version of that same number ("1.00 m" - "15.00 m")in the 2nd column, while items 16-30 should be blank in the first column and show "not set" in the second. 

You will see more errors in the list if you scroll around a bit, due to possibly related bug #42043.

Tested with Forms 2.2 and 2.3 with the same results.

## 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 2 tim.ahrentlov 2017-01-09 14:35:13 UTC
I have issues as well. Datatrigger setters does not always fire.
Comment 3 Stephane Delcroix 2017-06-13 09:22:40 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.
Comment 4 Namyslaw Szymaniuk 2017-06-13 09:36:31 UTC
Why someone has removed my comment, that DataTriggers works fine till 2.3.3, and starting from 2.3.4 (including 2.3.5) they are working randomly for me?

<Label>
  <Label.Triggers>
    <DataTrigger TargetType="Label" Binding="{Binding ViewMode}" Value="{x:Static views:ViewMode.ReadOnly}">
      <Setter Property="Text" Value="ReadOnly Mode}" />
    </DataTrigger>
    <DataTrigger TargetType="Label" Binding="{Binding ViewMode}" Value="{x:Static views:ViewMode.Edit}">
      <Setter Property="Text" Value="Edit Mode" />
    </DataTrigger>
    <DataTrigger TargetType="Label" Binding="{Binding ViewMode}" Value="{x:Static views:ViewMode.New}">
      <Setter Property="Text" Value="New Mode" />
    </DataTrigger>
  </Label.Triggers>
</Label>


What da hak is going on here! C'mon!
Comment 5 Namyslaw Szymaniuk 2017-06-13 09:37:08 UTC
And for the consistency - it TOTALLY NOT *RESOLVED ANSWERED*!
Comment 6 Stephane Delcroix 2017-06-13 11:22:54 UTC
@Namyslaw:
- I don't see any comment missing (you might not see comment #1, as it's private, but it's not the one you are looking for)
- Please open a new bug for your issue, as it's unrelated to the one reported here. Let me now when it's done, and I'll look at it.
Comment 7 Arne De Vreese 2017-06-14 09:05:46 UTC
Thank you for the clarifications. This makes sense. Using a converter was exactly what we did after we discovered this “problem”.