OnAppearing() not doing the FadeTo

CRoyCRoy Member ✭✭
edited June 2018 in Xamarin.Forms

I have a simple label which I would like to fade in. I have a StackLayout with 2 labels, I would like one to fly into view.

This is the XAML:

<StackLayout>
    <Label x:Name="FlyText"
        Text="I want to fly"
         FontFamily="Arial"
         FontSize="Large"
          />
    <Label x:Name="Other"
         Text="View this!"
         FontSize="Medium" />
</StackLayout>

And I added this to the code:

Option1:(the text just waits and appears all of a sudden)

protected override void OnAppearing()
{
      base.OnAppearing();
      animeMe();
}

 async void animeMe()
{
      await FlyText.FadeTo(1, 7000, Easing.Linear);
}

Option2:(the text just waits and appears all of a sudden)

 protected override void OnAppearing()
{
      base.OnAppearing();
      FlyText.FadeTo(1, 7000, Easing.Linear);
}

Is this a visual studio bug? Xamarin is not working all that well for me. I have the community Edition as I am just starting. The only emulator that works is an Android_Accelerated_X86_Nougat.

Tagged:

Best Answers

  • JGoldbergerJGoldberger US Xamurai
    edited June 2018 Accepted Answer

    @CRoy

    Don't you want to have the starting opacity 0? E.g.:

    <StackLayout>
        <Label x:Name="FlyText"
            Text="I want to fly"
             FontFamily="Arial"
             FontSize="Large"
             Opacity="0"  <!-- Set starting opacity to 0 -->
              />
        <Label x:Name="Other"
             Text="View this!"
             FontSize="Medium" />
    </StackLayout>
    

    Doing that both options work. But really, to follow async best practices, you should await all async method calls. E.g.:

    Option1:

    protected override async void OnAppearing()
    {
          base.OnAppearing();
          await animeMeAsync();
    }
    
     async void animeMeAsync()
    {
          await FlyText.FadeTo(1, 7000, Easing.Linear);
    }
    

    Option2:

     protected override async void OnAppearing()
    {
          base.OnAppearing();
          await FlyText.FadeTo(1, 7000, Easing.Linear);
    }
    

Answers

  • CRoyCRoy Member ✭✭
    edited June 2018

    Sorry the XAML did not copy over

    EDIT: Corrected XAML/Code in original post.

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai
    edited June 2018 Accepted Answer

    @CRoy

    Don't you want to have the starting opacity 0? E.g.:

    <StackLayout>
        <Label x:Name="FlyText"
            Text="I want to fly"
             FontFamily="Arial"
             FontSize="Large"
             Opacity="0"  <!-- Set starting opacity to 0 -->
              />
        <Label x:Name="Other"
             Text="View this!"
             FontSize="Medium" />
    </StackLayout>
    

    Doing that both options work. But really, to follow async best practices, you should await all async method calls. E.g.:

    Option1:

    protected override async void OnAppearing()
    {
          base.OnAppearing();
          await animeMeAsync();
    }
    
     async void animeMeAsync()
    {
          await FlyText.FadeTo(1, 7000, Easing.Linear);
    }
    

    Option2:

     protected override async void OnAppearing()
    {
          base.OnAppearing();
          await FlyText.FadeTo(1, 7000, Easing.Linear);
    }
    
  • Nadjib_BaitNadjib_Bait DZMember ✭✭✭✭

    Because your Label has already an opacity of 1, so it can't be faded to 1. Make its opacity 0 (in Xaml or before calling FadeTo).

  • Nadjib_BaitNadjib_Bait DZMember ✭✭✭✭

    Oh didn't see @JGoldberger answer. @CRoy please make his reply an answer so people know your question has been answered.

  • CRoyCRoy Member ✭✭

    Wow you guys are great! I am now less discouraged by Xamarin. Thank you!

Sign In or Register to comment.