Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Xamarin Forms 1.3 Triggers Bug

$
0
0

I’ve been playing with Xamarin Forms 1.3 new features to see what I can do with them and found a bug using Style Triggers in Xaml. 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.”

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.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>