Xamarin XAML 数据触发器动画

Ian*_*ink 4 animation xaml xamarin xamarin.forms

我已经定义了一个动画作为一个资源,当通过这样的 EventTrigger 调用时它可以工作:

  <ContentPage.Resources>
    <ResourceDictionary>
        <animations:StoryBoard x:Key="FadeInLogo" Target="{x:Reference Logo}">
            <animations:FadeToAnimation Opacity="1" Duration="700" />
        </animations:StoryBoard>
    </ResourceDictionary>   
   <ContentPage.Resources>
Run Code Online (Sandbox Code Playgroud)

然后

<ContentPage.Triggers>
    <EventTrigger Event="Appearing">
        <triggers:BeginAnimation  Animation="{StaticResource FadeInLogo}" />
Run Code Online (Sandbox Code Playgroud)

然而

当我尝试通过 DataTrigger 调用相同的动画时,编译器说需要 TargetType 的属性来创建 DataTrigger 对象???

    <DataTrigger Binding="{Binding IsOkToLogin}" Value="true" >
        <DataTrigger.EnterActions >
            <triggers:BeginAnimation  Animation="{StaticResource FadeInLogo}"></triggers:BeginAnimation>
        </DataTrigger.EnterActions>
    </DataTrigger>
Run Code Online (Sandbox Code Playgroud)

Rud*_*ano 5

每个触发器必须(重新)定义 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>
Run Code Online (Sandbox Code Playgroud)