虽然这是一个解决方案并且有效,但它的性能似乎并不好需要另一个答案。
为了加快性能我现在 tempNumItemsPerPage = tempNumItemsPerPage -2;
1) 在构造函数中为scrollchange添加了一个事件处理程序
public ViewName()
{
InitializeComponent();
// Handler to add scroll change event
Items.AddHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler(Items_ScrollChanged));
Init();
}
2) 将事件添加到我的列表视图中
<ListView ScrollViewer.ScrollChanged="OrderItems_ScrollChanged">
3)添加滚动更改代码
private void OrderItems_ScrollChanged(object sender, ScrollChangedEventArgs scrollChangedEventArgs)
{
ScrollViewer scrollViewer = Extensions.WPFExtensions.GetChildOfType<ScrollViewer>(Items);
if (scrollViewer.ComputedHorizontalScrollBarVisibility == Visibility.Visible)
{
GetItemsOnPage();
tempNumItemsPerPage--;
}
}
我唯一的问题是每次查看滚动条是否关闭时都会重置页面[肉眼不可见]。
public static class WPFExtensions
{
public static T GetChildOfType<T>(this DependencyObject depObj)
where T : DependencyObject
{
if (depObj == null) return null;
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
var child = VisualTreeHelper.GetChild(depObj, i);
var result = (child as T) ?? GetChildOfType<T>(child);
if (result != null) return result;
}
return null;
}
}