Closed chetanraj81 closed 4 years ago
What is the problem? Animations should always play from the beginning
I am trying to achieve an animated check box, I have created boolean property.
It is working but when focus on page from other page, animation plays from begin to end.
This is happening in Shell page, If I use tabbed page, It works perfectly.
My purpose is to play an animation till frames are set if value is true.
Thanks in advance.
Model
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
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;
}
}
Control
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" />
🐛 Bug Report
On Shell page, animation plays from beginning. Tried to get answer from Xamarin forum but didnt get the same
https://forums.xamarin.com/discussion/comment/420152
Expected behavior
Reproduction steps
Configuration
Version: 1.x
Platform: