Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

A Property resets to default when multiple Triggers setting it to the same value #1412

Open
danielkatz opened this issue Dec 17, 2017 · 9 comments

Comments

@danielkatz
Copy link

danielkatz commented Dec 17, 2017

Description

When two Triggers setting a property to the same (non-default) value on different conditions, after the handoff between the last and the first, the actual value resets to default.

Steps to Reproduce

<Label Text="Defaults in two clicks" 
    VerticalOptions="Center" 
    HorizontalOptions="Center">

    <Label.Triggers>

        <DataTrigger TargetType="Label" Binding="{Binding Source={x:Reference me}, Path=FlipFlop}" Value="False">
            <DataTrigger.Setters>
                <Setter Property="TextColor" Value="Red" />
            </DataTrigger.Setters>
        </DataTrigger>

        <DataTrigger TargetType="Label" Binding="{Binding Source={x:Reference me}, Path=FlipFlop}" Value="True">
            <DataTrigger.Setters>
                <Setter Property="TextColor" Value="Red" />
            </DataTrigger.Setters>
        </DataTrigger>

    </Label.Triggers>
</Label>

<Button Clicked="FlipTheFlop" Text="Click" />

private void FlipTheFlop(object sender, EventArgs e)
{
    FlipFlop = !FlipFlop;
}

Expected Behavior

Label will stay red after any number of clicks on the button

Actual Behavior

Label will become its default color after two clicks on the button

Basic Information

  • Version with issue: Xamarin.Forms 2.4.0
  • IDE: VS 15.5.1
  • Platform Target Frameworks:
    • Android: 8.0

Reproduction Link

https://github.com/mmcubit/SameValueTriggerBugRepro

First reported on bugzilla: https://bugzilla.xamarin.com/show_bug.cgi?id=60209

@PaulVrugt
Copy link

I'm running into the same issue. Any workaround?

@jgold6
Copy link
Contributor

jgold6 commented Nov 2, 2018

This appears to be the same issue posted on the forums: https://forums.xamarin.com/discussion/141997/datatrigger-only-occurs-once-per-value#latest

@samhouts samhouts added the inactive Issue is older than 6 months and needs to be retested label May 1, 2019
@Zure1
Copy link

Zure1 commented May 29, 2019

Still having a problem which might be related to this issue. I'm having two DataTriggers for a BackgroundColor Property for a boolean (true/false). When calling PropertyChanged and the value has changed, BackgroundColor is set to default, even tho my triggers are assigned like this:

true = red
false = white

Using Xamarin.Forms 3.4.0.1029999

@SittenSpynne
Copy link

I'm having the same issue in Xamarin Forms 4.2.0.778463. It seems if there are multiple DataTriggers looking at the same property, the last one wins.

@mojazu
Copy link

mojazu commented Dec 12, 2019

Any updates on this bug?

I am currently facing a most probably related issue. I got an entry with 2 Triggers on the "IsFocused" property that changes the Text according to the True or False value. The problem is that after entering some text and then deselecting/selecting the entry, the string format is applied as expected, but then the entry text resets to the older value!

<Entry Text="{Binding Progress, StringFormat='{}{0}%'}">
    <Entry.Triggers>
        <Trigger TargetType="Entry" Property="IsFocused" Value="False">
            <Setter Property="Text" Value="{Binding Progress, StringFormat='{}{0}%'}" />
        </Trigger>
        <Trigger TargetType="Entry" Property="IsFocused" Value="True">
            <Setter Property="Text" Value="{Binding Progress}" />
        </Trigger>
    </Entry.Triggers>
</Entry>

Using Xamarin.Forms 4.3.0.991221

@SOliasS
Copy link

SOliasS commented Jan 15, 2020

@mojazu try to move one trigger as default value.

<Entry Text="{Binding Progress, StringFormat='{}{0}%'}">
    <Entry.Triggers>
        <Trigger TargetType="Entry" Property="IsFocused" Value="True">
            <Setter Property="Text" Value="{Binding Progress}" />
        </Trigger>
    </Entry.Triggers>
</Entry>

Similar issue:
https://forums.xamarin.com/discussion/20040/disabled-button-style

@samhouts samhouts removed the inactive Issue is older than 6 months and needs to be retested label Mar 18, 2020
@samhouts
Copy link
Member

This issue doesn't seem to have had any activity in a long time. We're working on prioritizing issues and resolving them as quickly as we can. To help us get through the list, we would appreciate an update from you to let us know if this is still affecting you on the latest version of Xamarin.Forms, since it's possible that we may have resolved this as part of another related or duplicate issue. If we don't see any new activity on this issue in the next 30 days, we'll evaluate whether this issue should be closed. Thank you!

@samhouts samhouts added the s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. label Jul 13, 2020
@SOliasS
Copy link

SOliasS commented Jul 17, 2020

tested it with a button and seems to be working now (Forms 4.7.0.1142):

<Button Text="test" IsEnabled="{Binding IsVis}">
            <Button.Triggers>
                <Trigger TargetType="Button" Property="IsEnabled" Value="False">
                    <Setter Property="BackgroundColor" Value="SandyBrown" />
                </Trigger>
                <Trigger TargetType="Button" Property="IsEnabled" Value="True">
                    <Setter Property="BackgroundColor" Value="Coral" />
                </Trigger>
            </Button.Triggers>
        </Button>

@hartez hartez removed the s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. label Jul 21, 2020
@samhouts samhouts added this to the 5.0.0 milestone Aug 13, 2020
@samhouts samhouts removed this from the 5.0.0 milestone Nov 2, 2020
mattleibow added a commit that referenced this issue Jan 28, 2021
Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
@lhughey
Copy link

lhughey commented Apr 30, 2021

This issue is still present in v4.8.1687 and 5.0.0.2012. My ugly work around is to use values in setters that are basically the same, but resolve to same value. For instance, these are the values that I'm pulling into separate conditions for my trigger.
<Color x:Key="ButtonInactiveColor">#8598AA</Color> <Color x:Key="ButtonInactiveColor1">#8598AB</Color> <Color x:Key="ButtonInactiveColor2">#8598AC</Color> <Color x:Key="ButtonInactiveColor3">#8598AD</Color>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests