Привязываемые свойства Xamarin Lott ie animation - PullRequest
0 голосов
/ 01 августа 2020

Я пытаюсь установить анимированный флажок, я создал логическое свойство.

Он работает, но при фокусировке на странице с другой страницы анимация воспроизводится от начала до конца.

Моя цель - воспроизвести анимацию до тех пор, пока кадры не будут установлены, если значение истинно.

Заранее спасибо.

Модель

public  class WishListItem
{
    public string Art_code { get; set; }
    public string ImageUrl { get; set; }

    private bool _SendRequest;
    public bool SendRequest { get => _SendRequest; set { _SendRequest = value; RaisePropertyChanged(); } }

    public event PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChanged([CallerMemberName] string propertyName = "")
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}

VM

public class WishList: INotifyPropertyChanged
{
    private ObservableCollection<WishListItem> _WishCount;

    public ObservableCollection<WishListItem> WishCount {
        get => _WishCount;
        set
        {
            _WishCount = value;
            RaisePropertyChanged();
        }
    }

    public WishList()
    {
        WishCount = new ObservableCollection<WishListItem>();
        WishCount = GetItems().Result;
    }

    public event PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChanged([CallerMemberName] string propertyName = "")
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }

    public async Task<ObservableCollection<WishListItem>> GetItems()
    {
        foreach (var i in WishListService.WishListNew)
        {
            WishCount.Add(i); //Adding data 
        }

        return WishCount;
    }
}

Контроль

public class CustomCheckBox : AnimationView, IDisposable
{
    public string AnimationFile { get; set; }

    public CustomCheckBox()
    {
        Animation = "check.json";
        OnClick += Checkbox_OnClick;
    }

    public static BindableProperty IsCheckedProperty = BindableProperty.Create(
        nameof(IsChecked), typeof(bool), typeof(CustomCheckBox), defaultBindingMode: BindingMode.TwoWay,
        propertyChanged: IsCheckedChanged);

    public bool IsChecked
    {
        get { return (bool)GetValue(IsCheckedProperty); }
        set { SetValue(IsCheckedProperty, value); }
    }

    private static void IsCheckedChanged(BindableObject bindable, object oldValue, object newValue)
    {
        //   var cb = (CustomCheckBox)bindable;
        if (!(bindable is CustomCheckBox cb))
            return;

        if ((bool)newValue)
        {
            // cb.Play();
            cb.PlayFrameSegment(1, 50);
        }
        else
        {
            cb.PlayFrameSegment(1, 5);
            cb.IsPlaying = false;
        //    cb.Reset();
        }
    }

    void Reset()
    {
        Animation = null;
        Animation = AnimationFile;
    }

    void Checkbox_OnClick(object sender, EventArgs e)
    {
        IsChecked = !IsChecked;
    }

    public void Dispose()
    {
      OnClick -= Checkbox_OnClick;
    }
}

Xaml

<controls:CustomCheckBox x:Name="CustCheck" Grid.Row="0"  Grid.Column="1" VerticalOptions="End"                          
          IsChecked="{Binding SendRequest, Mode=TwoWay}" HeightRequest="35" WidthRequest="35" />
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...