【问题标题】:How to Animate ListView items in Xamarin Forms?如何为 Xamarin 表单中的 ListView 项目设置动画?
【发布时间】:2021-11-30 11:23:11
【问题描述】:

我想在通过 API 调用添加列表项后对其进行动画处理。但仅在首次加载时为其设置动画。

【问题讨论】:

    标签: listview animation xamarin.forms


    【解决方案1】:

    要访问 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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-15
      • 1970-01-01
      • 2019-10-17
      • 1970-01-01
      相关资源
      最近更新 更多