【发布时间】:2021-11-30 11:23:11
【问题描述】:
我想在通过 API 调用添加列表项后对其进行动画处理。但仅在首次加载时为其设置动画。
【问题讨论】:
标签: listview animation xamarin.forms
我想在通过 API 调用添加列表项后对其进行动画处理。但仅在首次加载时为其设置动画。
【问题讨论】:
标签: listview animation xamarin.forms
要访问 ViewCell,您可以使用 ViewCell 元素上的 Appearing 事件。您可以在 Scrolled 事件上设置一个标志,以防止后续 Appearing 触发器出现动画。
<ListView Scrolled="listView_Scrolled" ItemsSource="{Binding Items}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell Appearing="ViewCell_Appearing">
[Content Here]
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
private bool scrolled = false;
...
void ViewCell_Appearing(object sender, EventArgs e)
{
if (!scrolled)
{
ViewCell cell = (ViewCell)sender;
CustomAnimation(cell);
}
}
void listView_Scrolled(object sender, ScrolledEventArgs e)
{
scrolled = true;
}
【讨论】: