RadListView - 滚动到特定的 y 位置

RadListView - scroll to a specific y-position

在 RadListView 中,是否可以滚动到特定的 y 位置。

问题是如果我从 RadListView 页面导航到另一个页面然后返回 - 它初始化到列表视图的顶部。我更喜欢用户在导航到另一个页面之前所处的相同 y 位置。

我认为有一种滚动到项目的方法 - 但这不一定是相同的 y 位置。

您可以使用可观察的 ViewModel 缓存您的索引并在需要时传递它(在本例中为您的列表的 loaded 事件 -届时用户将 return 返回列表页面并加载列表)

例如打字稿

page.ts

export function onListLoaded(args: RadListwModule.ListViewEventData) {
    list = <RadListwModule.RadListView>args.object;

    if (list.items) {
        list.scrollToIndex(roversViewModel.get("cachedIndex"));
    }

    list.refresh();
}

export function onItemTap(args: RadListwModule.ListViewEventData) {
    var tappedItemIndex = args.itemIndex;

    // "cache" the index of our tapped  item
    roversViewModel.set("cachedIndex", tappedItemIndex);

    // navigate to  details page or do what you want to do on itemTap
    frame.topmost().navigate(navEntry);
}

page.xml

 <lv:RadListView items="{{ dataItems }}" loaded="onListLoaded" itemTap="onItemTap">

第一次加载列表时也给你的cachedIndex initial value of 0

示例基于 this POC app。 请注意,这与滚动到确切的 y 位置并不完全相同,但您可以修改逻辑并通过获取单元格相对位置偏移量进一步滚动到确切位置。