I am trying to calculate scroll speed of ScrollViewer using the VerticalOffset value at refresh rate of once per 100ms. The problem is that the VerticalOffset value doesn't update in realtime. So every second value is same as the last one. I even tried scrollviewer.UpdateLayout(); or this.UpdateLayout(); but still the no change.
Here is the code :
void Timer_Tick(object sender, EventArgs e)
{
Dispatcher.BeginInvoke(() =>
{
this.UpdateLayout();
double current_position = scrollviewer.VerticalOffset;
speed = (current_position - last_position);
last_position = current_position;
last_speed = speed;
Speed_text.Text = "Speed : " + speed.ToString();
});
}
I want to get the exact VerticalOffset. Even if the refresh rate is once per 10 ms.
Update:
So I tried to replace scrollviewer with viewportcontrol as longlistselector also uses it. Results were good. I got realtime values from viewportcontrol.ViewPort.Top.