xamarin - Xamarin.forms - 滚动时“附加”StackLayout
问题描述
我正在尝试从引导程序中“附加”效果。当用户滚动页面时,我想StackLayout
停在他父母的顶部。
有什么办法吗?
这就是我要问的(我在这个例子中使用视差效果):
[
谢谢。
解决方案
我的评论“为什么不使用具有内置此功能的分组的 ListView?” 部分正确。
使用带有分组的 ListView 将自动在 iOS 上提供“Sticky Header”功能,但在 Android 上不提供。
因此,对于 iOS,下一个代码将起作用:
public class ToysList : List<Toy>
{
public string Header { get; set; }
public List<Toy> Toys => this;
}
public class Toy
{
public string Name { get; set; }
}
// Initialise Toys in your ViewModel
<ListView
ItemsSource="{Binding Toys}"
IsGroupingEnabled="true">
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding Header}" />
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding Name}" />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
对于 Android,您必须创建一个自定义渲染器,幸运的是github 上有一个很好的示例。
推荐阅读
- python - 使用 cython 和 cythonize 从 python 调用 C++ 函数
- javascript - JavaScript 比较字符串,使字母排在其他字符之前
- rust - 如何编写经线日志?
- php - Time() 按 5 分钟选择
- c++ - 在'rw_ssid'中获取成员'length'的错误请求,它是非类类型'char *'
- javascript - Firestore 获取数据一次然后更新。数据快照的循环
- php - prestashop 模块配置页面中的 categoryChoiceTree
- reactjs - React Native:如何从按钮传递道具?
- android - firebase 消息 onCreate 未调用
- eclipse - 导入 Maven 项目正在改变 src/test/resource 结构