简体   繁体   English

Xamarin形成标签动画后如何保留标签文本

[英]Xamarin forms how to keep label text after label animation

I would like to figure out, how to keep my label text appear after label animation completion. 我想弄清楚如何在标签动画完成后保持标签文本出现。 My idea is that I have Label on top and Entry field behind it. 我的想法是,我在顶部有标签,在其后面有输入字段。 Until there isn't any text in entry, my label is empty, but when I starting to type my label appear with animation over and over after each newly typed character. 直到没有输入任何文本,我的标签都是空的,但是当我开始键入标签时,每个新键入的字符之后都会反复出现动画。 I already did that, but I wan't that it will appear with animation one time, and then keep showing my regular label without repeating animation. 我已经做过,但是我不希望它一次出现在动画中,然后继续显示我的常规标签而无需重复动画。 Because now my label shows with animation and do no keep, it disappears immediately. 因为现在我的标签带有动画显示并且不保留,所以它立即消失了。

Here is my xaml code: 这是我的xaml代码:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Project.MyPage">
  <ContentPage.Content>
    <StackLayout Padding="7,7,7,7" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Spacing="0">
              <StackLayout BackgroundColor="White">
              <Label x:Name="NameText"  />
              <Entry x:Name="Name"  />
              </StackLayout>                    
    </StackLayout>  
  </ContentPage.Content>
</ContentPage>

and here is my C# code with EventHandler: TextChange 这是我的带有EventHandler的C#代码:TextChange

public MyPage()
{
   InitializeComponent();
   Name.TextChanged += Name_TextChanged;
}
private async void Name_TextChanged(object sender, TextChangedEventArgs e)
{
   NameText.Animate("nameAnimation", new Animation(v => NameText.Scale = v, 1, 2, Easing.SpringIn));
   NameText.Text = "MyLabel";
}

How to my label appear and complete animation action only one time? 如何仅一次出现我的标签并完成动画动作? Thank you for answers or suggestions. 感谢您的回答或建议。

Detach your handler after the animation: 动画后分离处理程序:

async void Name_TextChanged(object sender, TextChangedEventArgs e)
{
  NameText.Animate("nameAnimation", new Animation(v => NameText.Scale = v, 1, 2, Easing.SpringIn));
  NameText.Text = "MyLabel";
  Name.TextChanged -= Name_TextChanged;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM