【问题标题】:Xamarin.forms - "Affix" StackLayout when scrollingXamarin.forms - 滚动时“附加”StackLayout
【发布时间】:2018-06-12 20:36:27
【问题描述】:

我正在尝试从引导程序中“附加”效果。当用户滚动页面时,我希望StackLayout 停在其父级的顶部。

有什么办法吗?

这就是我要问的(我在这个例子中使用了视差效果):

[

谢谢。

【问题讨论】:

  • 为什么不使用具有内置此功能的分组列表视图?
  • @EvZ 有吗?我不知道。我想如果你分享这样的答案,它应该是被接受的。

标签: xamarin scroll xamarin.forms stacklayout bootstrap-affix


【解决方案1】:

我的评论“为什么不使用带有内置此功能的分组的 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,您必须创建一个自定义渲染器,幸运的是有一个 good example on github

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-17
    相关资源
    最近更新 更多