0

I have several items in a list view in WPF. I'm wanting to add some items to the next "page" when they reach beyond the viewing area. However, I don't want scrolling available. I disable the scrolling.

<ListView ScrollViewer.HorizontalScrollBarVisibility="Disabled">

I don't want scrolling at all, I only want to know if there are items beyond the scrolling. Currently I limit the list by number of items on the page, however my items are not same size nor would I know the size of the screen so this needs to be adjustable.

4

1 回答 1

0

虽然这是一个解决方案并且有效,但它的性能似乎并不好需要另一个答案

为了加快性能我现在 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;

    }
}
于 2018-11-16T15:46:08.260 回答