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

Multiple Custom TickProvider in TimelineViewDefinition

3 Answers 77 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Rinku
Top achievements
Rank 1
Rinku asked on 11 Apr 2018, 09:51 AM

Hello,

I have used the SDK Samples browser example MonthTickProvider and obtained the CustomMonthTickProvider class to display the Month names in the GroupTickLength. On similar lines, I have managed to create Weekly tick provider that displays the Week Number and Quarter tick provider that displays the Quarter of the year. These providers alone work fine when put as GroupTickLegth.

However, I have to display Week tick provider in the MajorTickLength along with Month in GroupTickLength. The user can also switch between having Month in MajorTickLength and Quarter in GroupTickLength.

I tried the change the SDK Browser example itself and I am facing must be non-negative.

The following code block is what I am trying to achieve:

<telerik:RadScheduleView AppointmentsSource="{Binding Appointments, Source={StaticResource ViewModel}}">
    <telerik:RadScheduleView.ViewDefinitions>
                <telerik:TimelineViewDefinition VisibleDays="365"
                                                MinTimeRulerExtent="8000">
                    <telerik:TimelineViewDefinition.GroupTickLength>
                        <example:CustomMonthTickProvider />
                    </telerik:TimelineViewDefinition.GroupTickLength>
                    <telerik:TimelineViewDefinition.MajorTickLength>
                        <example:WeeklyTickProvider />
                    </telerik:TimelineViewDefinition.MajorTickLength>
              </telerik:TimelineViewDefinition>
    </telerik:RadScheduleView.ViewDefinitions>
</telerik:RadScheduleView>

 

If we replace the MajorTickLength with the same provider as in GroupTickLength, then there is no exception raised.

Here are my Week and Quarter provider classes

public class WeeklyTickProvider : ITickProvider
   {
       public string GetFormatString(IFormatProvider formatInfo, string formatString, DateTime currentStart)
       {
           var weekNumber = GetWeekNumber(formatInfo as CultureInfo, currentStart);
           return string.Format(formatInfo, "Week {0}", weekNumber);
       }
       private static int GetWeekNumber(CultureInfo formatInfo, DateTime currentStart)
       {
           var cultureInfo = formatInfo as CultureInfo;
           if (cultureInfo != null)
           {
               return cultureInfo.Calendar.GetWeekOfYear(currentStart, cultureInfo.DateTimeFormat.CalendarWeekRule, cultureInfo.DateTimeFormat.FirstDayOfWeek);
           }
           return 0;
       }
       public DateTime GetNextStart(TimeSpan pixelLength, DateTime currentStart)
       {
           var currentDate = currentStart.Date;
           var weekStart = CalendarHelper.GetFirstDayOfWeek(currentStart, DayOfWeek.Monday);
           if (weekStart == currentDate)
           {
               return weekStart.AddDays(7);
           }
           return weekStart;
       }
   }
   public class QuarterTickProvider : ITickProvider
   {
       public string GetFormatString(IFormatProvider formatInfo, string formatString, DateTime currentStart)
       {
           if (currentStart.Month >= 10)
           {
               return "Quarter 4";
           }
           else if (currentStart.Month >= 7)
           {
               return "Quarter 3";
           }
           else if (currentStart.Month >= 4)
           {
               return "Quarter 2";
           }
           else if (currentStart.Month >= 1)
           {
               return "Quarter 1";
           }
           return string.Empty;
       }
       public DateTime GetNextStart(TimeSpan pixelLength, DateTime currentStart)
       {
           if (currentStart.Month >= 10)
           {
               return new DateTime(currentStart.Year + 1, 1, 1);
           }
           else if (currentStart.Month >= 7)
           {
               return new DateTime(currentStart.Year, 10, 1);
           }
           else if (currentStart.Month >= 4)
           {
               return new DateTime(currentStart.Year, 7, 1);
           }
           else if (currentStart.Month >= 1)
           {
               return new DateTime(currentStart.Year, 4, 1);
           }
           return DateTime.Today;
       }

Another thing I noticed is that in the above , if I set GroupTick as month and MinorTick as , then there is no exception raised, But the desired output is not achieved.

Is there any way I could provide both GroupTickLength and MajorTickLength as my own custom tick providers. I have spent a lot of time to find a way but did not achieve the desired result.

 

3 Answers, 1 is accepted

Sort by
0
Rinku
Top achievements
Rank 1
answered on 16 Apr 2018, 04:19 AM

Hello,

Can anyone please help me on this? Maybe a minor change in my code might help what I am trying to achieve.

The attached image is what I am hoping to achieve using the code above.

0
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 16 Apr 2018, 09:01 AM
Hello Rinku,

Thank you for the provided code snippet.

To workaround this error I have made the following changes to the WeeklyTickProvider class. Check the following code snippet.
public class WeeklyTickProvider : ITickProvider
{
    List<string> weekCollection = new List<string>();
    public string GetFormatString(IFormatProvider formatInfo, string formatString, DateTime currentStart)
    {
        var weekNumber = GetWeekNumber(formatInfo as CultureInfo, currentStart);
 
        if (!weekCollection.Contains(weekNumber.ToString()))
        {
            weekCollection.Add(weekNumber.ToString());
            return string.Format(formatInfo, "Week {0}", weekNumber);
        }
            return string.Empty;
    }
 
    private static int GetWeekNumber(CultureInfo formatInfo, DateTime currentStart)
    {
        var cultureInfo = formatInfo as CultureInfo;
        if (cultureInfo != null)
        {
            return cultureInfo.Calendar.GetWeekOfYear(currentStart, cultureInfo.DateTimeFormat.CalendarWeekRule, cultureInfo.DateTimeFormat.FirstDayOfWeek);
        }
        return 0;
    }
 
    public DateTime GetNextStart(TimeSpan pixelLength, DateTime currentStart)
    {
        var currentDate = currentStart.Date;
        var weekStart = CalendarHelper.GetFirstDayOfWeek(currentStart, DayOfWeek.Monday);
        return weekStart.AddDays(7);
    }
}

You can observe that I have made changes to the GetFormatString method. This is because some weeks continues to the next month and the labels do not override its selves. You can additionally modify the GetFormatString so it fits in your main application. Give this approach a try and let me know if it works for you.

Regards,
Dinko
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Rinku
Top achievements
Rank 1
answered on 16 Apr 2018, 09:43 AM

Hello Dinko,

Thank you for the reply. 

Now I understand the problem and your solution is very helpful. I would need to do some tweaking on my QuarterTickProvider as well.

I can extend this approach to achieve what I require.

Thanks a lot!

Tags
ScheduleView
Asked by
Rinku
Top achievements
Rank 1
Answers by
Rinku
Top achievements
Rank 1
Dinko | Tech Support Engineer
Telerik team
Share this question
or