Xamarin Forms 1.3 Triggers Bug

I’ve been playing with Xamarin Forms 1.3 new features to see what I can do with them. Unfortunately I’ve found a few bugs which has proved a bit frustrating. In my last post I highlighted a bug with the new Behavior class here. I have also been trying out the new Style Triggers which I thought would more or less replicate the WPF Style Triggers. I’ve discovered that things are ok until you add more than one Trigger to Style.Triggers. For Example this will work no problem.

    <Style x:Key="labelStyle" TargetType="Label">
        <Style.Triggers>
            <Trigger Property="Text" TargetType="Label" Value="Foo">
                <Setter Property="BackgroundColor" Value="Red" />
            </Trigger>
        </Style.Triggers>
    </Style>

Here we expect the BackgroundColor to be Red if the Label Text is equal to ‘Foo’, and indeed this does work like so.

    <Label Text="Foo" Font="Small" Style="{StaticResource labelStyle}"  />

However, if we add another trigger condition to Triggers then things start to go wrong.

    <Style x:Key="labelStyle" TargetType="Label">
        <Style.Triggers>
            <Trigger Property="Text" TargetType="Label" Value="Foo">
                <Setter Property="BackgroundColor" Value="Red" />
            </Trigger>
            <Trigger Property="Font" TargetType="Label" Value="Small">
                <Setter Property="TextColor" Value="Olive" />
            </Trigger>
        </Style.Triggers>
    </Style>

Instead we get the exception “The given key was not present in the dictionary.”

I have posted this as a bug on the Xamarin Forms Forum here.

Interestingly I tried creating the Style in code in the code behind and it worked, so I’m assuming this is something related to the xaml parser or something like that.

In the meantime I can only use Triggers for a single Trigger in my xaml.

One thought on “Xamarin Forms 1.3 Triggers Bug

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s