代码之家  ›  专栏  ›  技术社区  ›  Timothy James

使用Exrin的动画

  •  2
  • Timothy James  · 技术社区  · 9 年前

    Exrin是否有办法处理文档中未涉及的动画,我是应该将动画附加到UI事件,还是应该使用诸如 attached behaviors ?

    1 回复  |  直到 9 年前
        1
  •  1
  •   Adam    9 年前

    动画是Xamarin表单的一部分,正如您所指出的,Exrin并没有专门处理它们。

    为了触发动画,并与MVVM纯粹主义者的心态保持一致,我会使用触发器。

    例如,创建一个触发器,只需要一个类

    public class BackgroundColorTrigger : TriggerAction<Entry>
    {    
         protected override void Invoke(Entry sender)
         {
             sender.BackgroundColor = Color.Yellow;
         }
    }
    

    // Add to Page Attributes (Above Trigger is in Namespace Mobile.Trigger)
    xmlns:trigger="clr-namespace:Mobile.Trigger"
    
    <Entry Text="{Binding EntryField}">   
        <Entry.Triggers>
            <EventTrigger Event="Focused">
                <trigger:BackgroundColorTrigger />
            </EventTrigger>
        </Entry.Triggers>
    </Entry>
    

    但是,根据需要改变触发器。

    动画是纯UI概念,因此保留在Exrin的视图项目中。XAML可以直接触发动画,逻辑可以放在触发器中。

    https://xamarinhelp.com/xamarin-forms-triggers-behaviors-effects/

    动画: https://xamarinhelp.com/custom-animations-in-xamarin-forms/

    推荐文章