How to detect scrollbar scrolled to the end?

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Arction_LasseP

bool001
Posts: 9
Joined: Wed Apr 04, 2018 3:06 am

How to detect scrollbar scrolled to the end?

Post by bool001 » Wed Apr 04, 2018 3:36 am

Hi, I have saw the ExampleThreadFedScrollBar example, but I want to resume realtime mode when scrollbar scrolled to the end.

So I must find a method to detect scrollbar scrolled to the end. Recently I havn't find any direct or convenient methods to do that.

But After several tests, I find a relationship between the scrollbar's Value, LargeChange, SmallChange and Maximum properties when scrolling, and I use it as the method to detect scrolled to the end.

Bellow is the detect code when scroll event fired:

Code: Select all

private void sb_Scroll(Object sender, Arction.Wpf.Charting.ScrollEventArgs e)
		{
            HorizontalScrollBar sb = sender as HorizontalScrollBar;
            if (sb == null) return;
            if (e.NewValue == (sb.Maximum - sb.LargeChange + sb.SmallChange))
            {
                buttonPauseResume.Content = "Pause";

                _isRealtime = true;
                _scrollPosition = e.NewValue;

                _chart.BeginUpdate();
                _chart.ViewXY.XAxes[0].ScrollMode = XAxisScrollMode.Scrolling;
                _chart.EndUpdate();
            }
            else
            {
                buttonPauseResume.Content = "Resume";

                _isRealtime = false;
                _scrollPosition = e.NewValue;

                _chart.BeginUpdate();

                //Set ScrollMode to None 
                _chart.ViewXY.XAxes[0].ScrollMode = XAxisScrollMode.None;

                // Call SetRange so that data is displayed correctly.
                _chart.ViewXY.XAxes[0].SetRange(e.NewValue / _samplingFrequency, e.NewValue / _samplingFrequency + _xLength);

                _chart.EndUpdate();
            }
        }
Is this method correct? Is there any direct or convenient methods to do that?

Thanks! :)

ArctionKestutis
Posts: 383
Joined: Mon Mar 14, 2016 9:22 am

Re: How to detect scrollbar scrolled to the end?

Post by ArctionKestutis » Wed Apr 04, 2018 11:23 am

Hi,

It is quite close. Your deduction is correct: whenever new points arrived the code updates HorizontalScrollBar.Maximum. If you want to keep scroll-tumb at the end, the Value field (HorizontalScrollBar.Value) is updated relatively to Maximum:

Code: Select all

sb.Value = sb.Maximum - sb.LargeChange +1;
Therefore, in your Scroll event handler it is enough to check

Code: Select all

            if (e.NewValue + sb.LargeChange >= sb.Maximum)
            {
                // resume scrolling
            }
Hope this helps.
All the best.

bool001
Posts: 9
Joined: Wed Apr 04, 2018 3:06 am

Re: How to detect scrollbar scrolled to the end?

Post by bool001 » Mon Apr 09, 2018 12:06 pm

OK, Thanks! That saves my time!