【问题标题】:Animate first child of ListView on xamarin forms以 xamarin 形式为 ListView 的第一个孩子设置动画
【发布时间】:2019-05-29 19:58:44
【问题描述】:

各位开发者您好,

我有一个 ListView,你猜对了,ViewCells。 作为关于如何使用应用程序的第一个教程的一部分,我需要为第一个 viewcell 的一些元素设置动画,以便用户可以理解单击该元素会做一些事情。

我尝试过使用 MVVM:

<StackLayout x:Name="{Binding CellName}" Orientation="Horizontal" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Margin="20">

然后

AccessPage[0].CellName = "TutorialCell";

但是

FindByName<ViewCell>("TutorialCell")

返回空值。

我只能访问绑定到 StackLayout 的项目,而不能访问 StackLayout 本身,所以我可以:

element.ScaleTo(1.05, 200);

我想错了吗? 谢谢。

【问题讨论】:

  • 我想我会从 ViewCell 继承并创建一个自定义视图单元格并将您的动画代码放在那里,您可以在此自定义视图单元格中创建自己的 BindableProperty 以指示它是教程单元格,还是只是监听 PropertyChanged 事件。另一种选择是使用数据模板选择器。
  • 谢谢@Bill,我正在研究这个方法,但是我如何访问“tutorialCell”来启动动画?我有一条消息解释了“闪烁”元素的作用,所以当消息出现时,元素应该“闪烁”

标签: listview xamarin.forms


【解决方案1】:

这对你有用吗?创建一个继承自 ListView 的新类并覆盖 SetupContent 方法:

public class MyListView : ListView
{
    public Cell FirstRow { get; set; }
    protected override void SetupContent(Cell content, int index)
    {
        if (index == 0) FirstRow = content;
        base.SetupContent(content, index);
    }
}

然后您可以访问自定义 ListView 的 FirstRow 属性。

【讨论】:

  • CollectionView 有没有等价物?
【解决方案2】:

你也可以投射:

ITemplatedItemsView<Cell> templatedItemsView = listView as ITemplatedItemsView<Cell>;
ViewCell firstCell = templatedItemsView.TemplatedItems[0] as ViewCell;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-03
    • 2013-12-11
    • 2020-08-07
    • 2021-02-15
    • 2021-11-30
    • 2015-08-03
    • 2017-03-11
    • 1970-01-01
    相关资源
    最近更新 更多