Xamarin XAML DataTrigger动画

时间:2018-08-29 03:33:28

标签: xaml animation xamarin xamarin.forms

我已将动画定义为一种资源,该资源在通过EventTrigger调用时可以正常工作,如下所示:

class GraphicUploader < Shrine
  include ImageProcessing::MiniMagick
  plugin :activerecord
  plugin :cached_attachment_data # for retaining the cached file across form redisplays
  plugin :restore_cached_data # re-extract metadata when attaching a cached file
  plugin :determine_mime_type
  plugin :remove_attachment

  def generate_location(io, context = {})
    name  = super # the default unique identifier

    if io.is_a?(File)
      initial_location  = io.to_path
      new_location      = initial_location.match(/(.*\/).*/)[1]
      final_location = [new_location + name].compact.join # returns original path
    else
      foo = [io.id].compact.join.to_s
    end

    end
  end
end

然后

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

但是

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

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

1 个答案:

答案 0 :(得分:2)

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