代码之家  ›  专栏  ›  技术社区  ›  Ian Vink

Xamarin XAML DataTrigger动画

  •  1
  • Ian Vink  · 技术社区  · 6 年前

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

    那么

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

    然而

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

        <DataTrigger Binding="{Binding IsOkToLogin}" Value="true" >
            <DataTrigger.EnterActions >
                <triggers:BeginAnimation  Animation="{StaticResource FadeInLogo}"></triggers:BeginAnimation>
            </DataTrigger.EnterActions>
        </DataTrigger>
    
    1 回复  |  直到 6 年前
        1
  •  5
  •   Rudy Spano    6 年前

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