Hi Bahram,
I assume that by "the scroll event of gantt view" you reference the attached ScrollBar.Scroll event. Please correct me if I'm wrong in this assumption.
If this is indeed the event you're handling, you need to invoke the logic for getting the visible dates through the Dispatcher's BeginInvoke method and specify DispatcherPriority.Render as the priority.
private void GanttView_Scroll(object sender, System.Windows.Controls.Primitives.ScrollEventArgs e)
{
Dispatcher.BeginInvoke(new Action(() =>
{
var ticks = this.GanttView.ChildrenOfType<MajorTickContainer>().ToList();
var visibleDates = new List<DateTime>();
for (int i = 0; i < ticks.Count(); i++)
{
var tick = ticks[i] as MajorTickContainer;
var vm = tick.DataContext as TickProxy;
var date = vm.DateTime;
if (tick.Visibility == Visibility.Visible)
{
visibleDates.Add(date);
}
}
var first = visibleDates.OrderBy(x => x.Date).First();
var last = visibleDates.OrderBy(x => x.Date).Last();
MessageBox.Show(string.Join(", ", visibleDates.OrderBy(x => x.Date).Select(x => x.Day)));
}), System.Windows.Threading.DispatcherPriority.Render);
}
Please give this a try and let me know if this delivers the expected result.
Regards,
Dilyan Traykov
Progress Telerik
Get
quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers.
Learn More.