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

week number on ganttview

2 Answers 196 Views
GanttView
This is a migrated thread and some comments may be shown as answers.
Kourosh
Top achievements
Rank 1
Kourosh asked on 11 Jun 2018, 03:12 AM

Hello Telerik,

How can I show week number on timerulerlines?

I am following your tutorial:

<telerik:RadGanttView.TimeRulerLines>
                <telerik:GroupTickLine>
                    <telerik:TickInterval Interval="OneMonth" FormatString="{}{0:MMMM, yyyy}" />
                </telerik:GroupTickLine>
                <telerik:MajorTickLine>
                    <telerik:TickInterval Interval="OneWeek" />
                </telerik:MajorTickLine>
                <telerik:MinorTickLine>
                    <telerik:TickInterval Interval="OneDay" FormatString="Day {0:dd}" />
                </telerik:MinorTickLine>
            </telerik:RadGanttView.TimeRulerLines>

but the week number is not displaying. just the word "Week" is showing!

Best Regards

kourosh

2 Answers, 1 is accepted

Sort by
1
Accepted
Martin Ivanov
Telerik team
answered on 13 Jun 2018, 01:45 PM
Hello Kourosh,

The .NET framework doesn't provide you with a format string that allows you to extract the number of the date's week. In order to achieve you requirement you can create a custom TickInterval and override its FormatValue() method. This will allow you to return a custom string. Here is an example in code:
public class CustomTickInterval : TickInterval
{
    protected override string FormatValue(Range<long> timeRange)
    {
        var rangeMiddle = timeRange.Start + ((timeRange.End - timeRange.Start) / 2);
        var date = new DateTime(rangeMiddle);
 
        System.Globalization.CultureInfo cul = System.Globalization.CultureInfo.CurrentCulture;
 
        int weekNum = cul.Calendar.GetWeekOfYear(date, System.Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
        return "Week " + weekNum;
    }
}
I used the approach for getting the week number shown in the following stackoverflow topic.

Then you can use the custom interval in XAML.
<telerik:MajorTickLine>
    <local:CustomTickInterval Interval="OneWeek"/>
</telerik:MajorTickLine>

Regards,
Martin Ivanov
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
Kourosh
Top achievements
Rank 1
answered on 14 Jun 2018, 05:30 AM

Thank you Martin,

It works like a charm! :)

Best Regards

Kourosh

Tags
GanttView
Asked by
Kourosh
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Kourosh
Top achievements
Rank 1
Share this question
or