Ian Vink
Ian Vink

Reputation: 68770

Xamarin XAML DataTrigger Animations

I have defined an Animation as a resource that works when called via an EventTrigger like this:

  <ContentPage.Resources>
    <ResourceDictionary>
        <animations:StoryBoard x:Key="FadeInLogo" Target="{x:Reference Logo}">
            <animations:FadeToAnimation Opacity="1" Duration="700" />
        </animations:StoryBoard>
    </ResourceDictionary>   
   <ContentPage.Resources>

Then

<ContentPage.Triggers>
    <EventTrigger Event="Appearing">
        <triggers:BeginAnimation  Animation="{StaticResource FadeInLogo}" />

However

When I try to call that same animation via a DataTrigger, the compiler says that a Property of TargetType is needed to create a DataTrigger object???

    <DataTrigger Binding="{Binding IsOkToLogin}" Value="true" >
        <DataTrigger.EnterActions >
            <triggers:BeginAnimation  Animation="{StaticResource FadeInLogo}"></triggers:BeginAnimation>
        </DataTrigger.EnterActions>
    </DataTrigger>

Upvotes: 4

Views: 1255

Answers (1)

Rudy Spano
Rudy Spano

Reputation: 1421

Each Trigger must (re)define the TargetType:

  <ContentPage.Triggers>
    <DataTrigger TargetType="ContentPage" Binding="{Binding IsOkToLogin}" Value="true" >
        <DataTrigger.EnterActions >
            <triggers:BeginAnimation  Animation="{StaticResource FadeInLogo}"></triggers:BeginAnimation>
        </DataTrigger.EnterActions>
    </DataTrigger>
  </ContentPage.Triggers>

Upvotes: 5

Related Questions