This is a migrated thread and some comments may be shown as answers.

How can I get first and last time(dates) that are currently visible(in sight) in time ruler?

7 Answers 97 Views
GanttView
This is a migrated thread and some comments may be shown as answers.
Bahram
Top achievements
Rank 1
Bahram asked on 07 Nov 2019, 07:35 PM

Hi there,

 

I would be appreciate your help with this.

Attached a screenshot that shows what I am looking for:

 

Thanks,

Bahram Afsharipoor

7 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 12 Nov 2019, 12:41 PM

Hi Bahram,

Thank you for the provided image.

You can get ahold of all dates in the viewport by getting all MajorTickContainer instances with the ChildrenOfType extension method.

            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)));
Please note that due to the control's UI virtualization mechanism, we exclude the containers whose Visibility is Collapsed.

Please give this a try and let me know if such an approach works for you.

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.
0
Bahram
Top achievements
Rank 1
answered on 14 Nov 2019, 09:47 PM

Hi Dilyan,

 

I appreciate you giving me this solution, it is exactly what I needed!

 

Regards,

Bahram Afsharipoor

0
Bahram
Top achievements
Rank 1
answered on 14 Jan 2020, 01:12 AM

Hi Dilyan,

 

I have found an issue with above code. When I click on repeat buttons (transparent areas) of gantt's horizontal scroll, I get a completely different set of visible dates. I don't know what is happening, can you please help me with that? 

Attached is a picture that shows the clicked areas of horizontal scroll.

 

Thanks,

Bahram

0
Dilyan Traykov
Telerik team
answered on 16 Jan 2020, 11:42 AM

Hi Bahram,

Thank you for the provided image.

I tried replicating the issue you described at my end by clicking the areas you referenced, however, the approach I proposed seems to return the correct dates each time.

I've attached the project I set up as well as a short recording of the result I observe at my end.

Could you please have a look and let me know if I'm missing something of importance?

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.
0
Bahram
Top achievements
Rank 1
answered on 20 Jan 2020, 11:17 PM

Hi Dilyan,

 

Your code works perfectly fine if I run it via the click event of that button you added to your attached project. However, I am trying to get visible dates of my gantt view through its scroll event. Basically as user scrolls horizontally, I want to be able to get current visible dates. If you try to run your code via the scroll event of gantt view, you will be able to reproduce the issue.

 

I am guessing that the datacontext of MajorTickContainer class gets updated after the scroll event of gantt view finished executing, am I right? If so, what do you suggest me to do? 

 

Thanks,

Bahram Afsharipoor

0
Accepted
Dilyan Traykov
Telerik team
answered on 21 Jan 2020, 12:58 PM

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.
0
Bahram
Top achievements
Rank 1
answered on 30 Jan 2020, 07:18 PM

Hi Dilyan,

 

Yes this is exactly what I needed, thank you for your help!

 

Thanks,

Bahram Afsharipoor

Tags
GanttView
Asked by
Bahram
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Bahram
Top achievements
Rank 1
Share this question
or