Xamarin.forms: A Property resets to default when multiple Triggers setting it to the same value

Created on 17 Dec 2017  路  8Comments  路  Source: xamarin/Xamarin.Forms

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

Xaml </> 4 bug

Most helpful comment

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.

All 8 comments

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

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

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.

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

@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

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!

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>
Was this page helpful?
0 / 5 - 0 ratings