Xamanimation icon indicating copy to clipboard operation
Xamanimation copied to clipboard

Help: What is the best approach for animating a object in View when using MVVM?

Open kerberosargos opened this issue 4 years ago • 0 comments

Hello,

I have a simple Xamarin Forms app. I am using Prism Forms. I would like to animate Label with basic fade animation in View, when its old value and new value is not equal. What is the best approach for animating a object in View? Thank you in advance.

MainPageViewModel.cs


public class MainPageViewModel : BindableBase
{
    public HomePageViewModel()
    {       
            Title = "First";
            ChangeTitle();
    }

    private async void ChangeTitle()
    {

        await Task.Delay(5000);

        if(Title == "First")
        {
            Title = "Second";
        }
        else
        {
            Title = "First";
        }

        ChangeTitle();
    }



    private string title;
    public string Title
    {
        get { return title; }
        set { SetProperty(ref title, value); }
    }

}

MainPage.xml

<ContentPage
    x:Class="SmapleApp.Views.MainPage"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:prism="http://prismlibrary.com"
    prism:ViewModelLocator.AutowireViewModel="True"
    Title="Main Page">

    <Label Text="{Binding Title}" />

</ContentPage>

kerberosargos avatar Mar 21 '20 16:03 kerberosargos