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

8 posts, 1 answers
  1. Bahram
    Bahram avatar
    24 posts
    Member since:
    Feb 2019

    Posted 07 Nov 2019 Link to this post

    Hi there,

     

    I would be appreciate your help with this.

    Attached a screenshot that shows what I am looking for:

     

    Thanks,

    Bahram Afsharipoor

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    1180 posts

    Posted 12 Nov 2019 Link to this post

    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.
  3. Bahram
    Bahram avatar
    24 posts
    Member since:
    Feb 2019

    Posted 14 Nov 2019 in reply to Dilyan Traykov Link to this post

    Hi Dilyan,

     

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

     

    Regards,

    Bahram Afsharipoor

  4. Bahram
    Bahram avatar
    24 posts
    Member since:
    Feb 2019

    Posted 13 Jan in reply to Dilyan Traykov Link to this post

    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

  5. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    1180 posts

    Posted 16 Jan Link to this post

    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.
  6. Bahram
    Bahram avatar
    24 posts
    Member since:
    Feb 2019

    Posted 20 Jan in reply to Dilyan Traykov Link to this post

    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

  7. Answer
    Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    1180 posts

    Posted 21 Jan Link to this post

    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.
  8. Bahram
    Bahram avatar
    24 posts
    Member since:
    Feb 2019

    Posted 30 Jan in reply to Dilyan Traykov Link to this post

    Hi Dilyan,

     

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

     

    Thanks,

    Bahram Afsharipoor

Back to Top