Bug 56515 - Data trigger setter does not fire in XF 2.3.4
Summary: Data trigger setter does not fire in XF 2.3.4
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.4
Hardware: Other Mac OS
: High blocker
Target Milestone: ---
Assignee: Stephane Delcroix
URL:
Depends on:
Blocks:
 
Reported: 2017-05-16 17:14 UTC by Matthew Richardson
Modified: 2018-02-17 06:28 UTC (History)
10 users (show)

Tags: ac uwp ios android datatrigger setter
Is this bug a regression?: Yes
Last known good build: 2.3.3.193


Attachments
Working on XF 2.3.3.193 (295.32 KB, application/zip)
2017-05-16 17:16 UTC, Matthew Richardson
Details
Broken on XF 2.3.4.231 (297.25 KB, application/zip)
2017-05-16 17:17 UTC, Matthew Richardson
Details
modified project (242.56 KB, application/zip)
2017-07-27 21:18 UTC, Jimmy [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 Matthew Richardson 2017-05-16 17:14:37 UTC
In XF 2.3.4 as part of the work to compile data triggers, it apppears setter functionality is broken in some cases.

When using a DataTrigger to set an image Source, the setter does not fire correctly. This may be similar to the behavior reported in #32896 and #42044. I believe this may be related to the work done in PR #648 and possibly PR #737.

Please see repro projects which demo working data trigger in 2.3.3.193 and broken in 2.3.4.231.
Note: For the repro projects, image assets included for Droid only so please test on Droid.
Comment 1 Matthew Richardson 2017-05-16 17:16:57 UTC
Created attachment 22207 [details]
Working on XF 2.3.3.193
Comment 2 Matthew Richardson 2017-05-16 17:17:23 UTC
Created attachment 22208 [details]
Broken on XF 2.3.4.231
Comment 3 Paul DiPietro [MSFT] 2017-05-17 15:04:17 UTC
Thanks for the reproductions. The issue also still occurs on 2.3.4.247. Updating to mark this as a regression.
Comment 4 Matthew Richardson 2017-06-01 15:19:22 UTC
Thanks Paul. Will this be addressed in XF 2.3.5?
Comment 5 Namyslaw Szymaniuk 2017-06-05 20:18:50 UTC
I faced the same problem at 2.3.5.239-pre3 - DataTrigger working randomly. At 2.3.3.193 it's working fine.

For me it's again CRITIAL issue.. again, as whole XF. Each update, new issues.
Comment 6 Matthew Richardson 2017-06-12 14:32:00 UTC
Paul - are you able to give us an update on this issue? Can we expect to see a fix in XF 2.3.5 or even better a hot-fix on 2.3.4?
Comment 7 Jimmy [MSFT] 2017-06-19 15:00:06 UTC
Bumping up the priority since this is a regression that is still present in recent versions.

2.3.6-nightly   BAD
2.3.5-pre3      BAD
2.3.4.247       BAD
2.3.3.193       GOOD
Comment 8 Matthew Richardson 2017-06-26 13:31:58 UTC
Regression still exists in XF 2.3.5-pre5.
I'm really hoping this will be fixed before XF 2.3.5-stable?
Comment 9 Namyslaw Szymaniuk 2017-06-26 13:33:35 UTC
Yep, for me at pre5 it's working at as pre3 - issue still exist.
Comment 10 Namyslaw Szymaniuk 2017-06-28 07:17:13 UTC
Any comment from XF team? Any chance for fix in stable 2.3.5?
Comment 11 Paul DiPietro [MSFT] 2017-06-28 13:29:44 UTC
We're looking into this.
Comment 12 Namyslaw Szymaniuk 2017-07-27 11:23:14 UTC
Any update? It a month has passed... and it's still **High blocker**.
Comment 13 Jimmy [MSFT] 2017-07-27 21:18:21 UTC
Created attachment 23855 [details]
modified project

I discussed this issue with the team and we determined that this is not a bug. The Image in the repro project has two DataTriggers attached that get fired and each change the Binding for the Source property. Even though this may have worked in previous versions, the behavior cannot be expected to be consistent for this kind of scenario. We cannot guarantee the order that the Binding changes will be applied and it may result in a broken state as seen here. 

One recommended approach is to bind Image.Source to a single property and update that binding when IsSelected is changed. This would eliminate the need for DataTriggers on the Image. Alternatively, you can set Image.Source to a default file name or binding and continue using a single DataTrigger that changes the Source. When the DataTrigger condition is not met, the Image will then use the default Source.

I've attached a modified version of the repro project that demonstrates both these methods. Hope this helps!
Comment 14 Matthew Richardson 2017-07-28 00:00:24 UTC
Thanks Jimmy. A couple of months back we went with the first workaround you mentioned and bind to a single property and update when IsSelected is changed.

However, I feel we may need to re-open this issue as this is not the only case where DataTriggers are failing in XF 2.3.4 and above.

Just as a small note, could this limitation please be added to the docs? If it is not supported using multiple triggers on a Image source, then this needs to be documented. Do similar limitations exist for other views and properties? This all would be useful information.

Thanks!
Comment 15 Namyslaw Szymaniuk 2017-07-28 06:30:47 UTC
Well, that's really strange.
It's it default understanding of .NET **DataTriggers**, that it's possible to set some property to *X*, but set it also to *Y*, based on **DataTriggers** contition?
I've multiple places in my app, where I'm doing it in that way...
Comment 16 Namyslaw Szymaniuk 2017-07-28 06:47:39 UTC
I see something similar here - https://bugzilla.xamarin.com/show_bug.cgi?id=30074 - where same property could be set with three different values.

I also dissagree with proposed "workaround" to set some property value "at start" and handle only *True* condition. What if there is enum with 3 or more values, and we want our control, to be different for each of them (by setting same property to different value, based on differnet enums)?
Comment 17 David Ortinau [MSFT] 2017-07-31 13:37:23 UTC
@Matthew please do reopen with a repro and a specific case. The title on this issue is overly broad and we need to get to specific cases. 

Agree, we will have docs update with more guidance around DataTriggers.


@Namyslaw sounds like your enum case is a candidate for a value converter (you could pass in values for each case), or having a proxy getter on your VM that does this logic.

The issue with binding multiple triggers to a single property is that the trigger's set/unset methods are async and as such cannot be predicted to maintain order when bound to the same property.

If you have specific cases for DataTriggers not working, please open independent Bugzilla reports so we can work with concrete examples and reproductions.