Animation 当图像源更改时,如何实现动画?
我正在处理xamarin.forms,希望在更改图像源时启动动画Animation 当图像源更改时,如何实现动画?,animation,xamarin.forms,Animation,Xamarin.forms,我正在处理xamarin.forms,希望在更改图像源时启动动画 <ListView > <ListView.ItemTemplate> <DataTemplate> <ViewCell> <Image Source="{Binding Favor
<ListView >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Image Source="{Binding FavoriteImage}" x:Name="favoriteImage">
<Image.GestureRecognizers>
TapGestureRecognizer Command="{Binding Source={x:Reference CurrentPage},Path=BindingContext.ClickLikedCommand}" CommandParameter="{Binding .}" NumberOfTapsRequired="1"/>
</Image.GestureRecognizers>
</Image>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
TapGestureRecognitzer命令=“{Binding Source={x:Reference CurrentPage},Path=BindingContext.ClickLikedCommand}”命令参数=“{Binding.}”NumberOfTapsRequired=“1”/>
图像源绑定到ViewModel中的变量,如果用户单击图像并从服务器获得成功响应,则图像源将被更改。然后,新图像将显示一些自定义动画,既然图像源已更改,我在哪里可以触发此动画?
我已经在线阅读了“Behavior”和“Trigger”教程,它似乎可以通过事件触发动画,但Image类没有这样的“SourceChanged”事件。您可以使用
OnPropertyChanged
方法:
public class ExImage : Image
{
protected override void OnPropertyChanged(string propertyName = null)
{
base.OnPropertyChanged(propertyName);
if (propertyName == nameof(Source))
Device.BeginInvokeOnMainThread(async () =>
{
await this.ScaleTo(1.2);
await this.ScaleTo(1);
});
}
}
您可以使用
OnPropertyChanged
方法:
public class ExImage : Image
{
protected override void OnPropertyChanged(string propertyName = null)
{
base.OnPropertyChanged(propertyName);
if (propertyName == nameof(Source))
Device.BeginInvokeOnMainThread(async () =>
{
await this.ScaleTo(1.2);
await this.ScaleTo(1);
});
}
}