Xamarin.forms: [Bug] Setters do not properly revert when used with multiple triggers

Created on 21 Aug 2019  路  3Comments  路  Source: xamarin/Xamarin.Forms

Description

When multiple style setters modify the same property the value is not properly reverted.

Steps to Reproduce

  1. Create a style with two triggers. The setters inside each of these triggers should modify the same property with different values. The example app uses two DataTriggers bound to boolean properties IsWarning and IsError. When these properties are set to true the FontColor is set to Orange or Red respectively. The starting text color is black.
  2. Toggle the first property to true. In the example app, this is the IsWarning property. The text color is now orange.
  3. Toggle the second property to true. In the example app, this is the IsError property. The text color is not red.
  4. Toggle the first property to false. In the example app, this is the IsWarning property. The text color remains red as expected.
  5. Toggle the second property to false. In the example app, this is the IsError property. The text color is reverted to Orange. However, the expected color to should be the default black text color.

Expected Behavior

The triggers appear to revert back to the previous value that was set when the trigger was applied. However, I would have expected that when none of the triggers match, the value should be reverted back to its default state.

I would have expected the behavior to match other XAML frameworks like WPF and UWP. In the attached solution I have also included a WPF app that shows the expected behavior.

Actual Behavior

The property's value is reverted back to the state it was in before the trigger matched.

Basic Information

  • Version with issue: 4.0.0.425677
  • Last known good version: N/A
  • IDE: Visual Studio 2019 version 16.1.4
  • Platform Target Frameworks:

    • iOS: 12.10

    • Android: 9.3

    • UWP: N/A

  • Android Support Library Version: 28.0.0.1
  • Nuget Packages: Default Xamarin and Xamarin.Essentials from a clean project
  • Affected Devices:

Screenshots


TriggerBug

Reproduction Link


SetterBug.zip

Additional information

This appears like it may be the same root cause as #5422
From looking at the source code it appears the issue stems from how Setter.UnApply is implemented. It appears to cache the current value from the property when it is applied and then set that value back in when the trigger no longer matches.

style 3 bug

Most helpful comment

Reproduces beautifully as described.

All 3 comments

Reproduces beautifully as described.

This bug also appears when a Style is derived from another Style and Triggers are added (override existing ones). Triggers cannot be used at all with this bug when it comes to a minimum of complex styling. Please fix this soon!

Any progress on this? Seems to still be an issue as of 4.6.0.1073

Was this page helpful?
0 / 5 - 0 ratings