Reputation: 24572
I have a content page that displays words. I get the words from the database, populate a view model which in turn changes label text through bindings and then this code makes the new words visible:
phrasesPageStackLayout.IsVisible = true;
After a few seconds this makes the words disappear:
phrasesPageStackLayout.IsVisible = false;
I get a new word and the process starts again.
In Xamarin.Forms is it possibly for me to make the words fade into view and fade out of view. For example over a period of 3 seconds?
Upvotes: 2
Views: 8419
Reputation: 987
You may also want to have a look at Xamanimation - you'll get standard animations right out of the box: https://github.com/jsuarezruiz/Xamanimation
Upvotes: 1
Reputation: 5313
I prefer use reusable approaches, then I've created an extension method to handle with this kind of need:
public static class VisualElementExtensions
{
public static async System.Threading.Tasks.Task FadeOut(this VisualElement element, uint duration = 400, Easing easing = null)
{
await element.FadeTo(0, duration, easing);
element.IsVisible = false;
}
public static async System.Threading.Tasks.Task FadeIn(this VisualElement element, uint duration = 400, Easing easing = null)
{
await element.FadeTo(1, duration, easing);
element.IsVisible = true;
}
}
You can use it in any VisualElement you wish (Button, Label, Layouts and so on) like this:
phrasesPageStackLayout.FadeOut (); /* I guess 1.5 seconds is too much time to this kind of purpose, but you can do `phrasesPageStackLayout.FadeOut (3000)` if you need. */
// Or
phrasesPageStackLayout.FadeIn (500, Easing.CubicOut)
I hope it helps you.
Upvotes: 2