简体   繁体   English

WPF Scrollviewer和ScrollChanged事件

[英]Wpf Scrollviewer and ScrollChanged event

My task is to create scrollviewer with images. 我的任务是创建带有图像的scrollviewer。 At first I dont want to load them all. 起初我不想全部加载它们。 I want to load 50 images and when the scroll slider is about half then load another 50 pictures and so on. 我想加载50张图像,并且当滚动条大约一半时再加载50张图片,依此类推。

My start point: 我的出发点:

        if (MyContent.VerticalOffset == MyContent.ScrollableHeight / 2 && MyContent.VerticalOffset != 0)
        {
            MessageBox.Show("Half");
        }

First problem is When i slide too fast, event doesn't fire. 第一个问题是,当我滑动得太快时,事件不会触发。 Maybe have already some solution for this task. 也许已经为该任务提供了一些解决方案。

You're only checking if VerticalOffset is equal to ScrollableHeight . 您仅在检查VerticalOffset是否等于ScrollableHeight User can avoid this one single spot by moving the scroll bar very fast. 用户可以通过快速移动滚动条来避免这一点。 Events are not fired that frequent, so you should check if VerticalOffset is past half. 不会频繁触发事件,因此您应该检查VerticalOffset是否超过一半。 You can achieve this by changing operator from == to >= : 您可以通过将运算符从==更改为>=

if (MyContent.VerticalOffset >= MyContent.ScrollableHeight / 2 && MyContent.VerticalOffset != 0)
{
    MessageBox.Show("Past Half");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM