How to remove leading 0 from single digits dates in month view?

5 posts, 0 answers
  1. Kjell
    Kjell avatar
    276 posts
    Member since:
    Jun 2010

    Posted 20 Nov 2011 Link to this post

    For example 01 should be 1, 02 should be 2, etc (this was default behavior on the scheduler).  I assume this can be done in a custom style template.  I am already using one so I think if you can just tell me which part to edit then it should be pretty easy.  Thank in advance.
  2. Dani
    Admin
    Dani avatar
    848 posts

    Posted 21 Nov 2011 Link to this post

    Hi Kjell,

    To change the string format of the month view time ruler item, you do not need a style selector. It will be more convenient for you to use the TimeRulerItemTemplateSelector . I copy here the templates of the selector for your convenience.

    <telerik:TimeRulerItemTemplateSelector x:Key="TimeRulerItemTemplateSelector">
        <telerik:TimeRulerItemTemplateSelector.HorizontalDayMajorItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding FormattedValue}" Margin="2" />
            </DataTemplate>
        </telerik:TimeRulerItemTemplateSelector.HorizontalDayMajorItemTemplate>
        <telerik:TimeRulerItemTemplateSelector.HorizontalDayMinorItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding FormattedValue}" Margin="2" />
            </DataTemplate>
        </telerik:TimeRulerItemTemplateSelector.HorizontalDayMinorItemTemplate>
        <telerik:TimeRulerItemTemplateSelector.HorizontalWeekMajorItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding FormattedValue}" Margin="2" />
            </DataTemplate>
        </telerik:TimeRulerItemTemplateSelector.HorizontalWeekMajorItemTemplate>
        <telerik:TimeRulerItemTemplateSelector.HorizontalWeekMinorItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding FormattedValue}" Margin="2" />
            </DataTemplate>
        </telerik:TimeRulerItemTemplateSelector.HorizontalWeekMinorItemTemplate>
        <telerik:TimeRulerItemTemplateSelector.VerticalDayMajorItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding FormattedValue}" Margin="0 2" MinWidth="54" TextAlignment="Right" />
            </DataTemplate>
        </telerik:TimeRulerItemTemplateSelector.VerticalDayMajorItemTemplate>
        <telerik:TimeRulerItemTemplateSelector.VerticalDayMinorItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding FormattedValue}" Margin="0 2" MinWidth="54" TextAlignment="Right" />
            </DataTemplate>
        </telerik:TimeRulerItemTemplateSelector.VerticalDayMinorItemTemplate>
        <telerik:TimeRulerItemTemplateSelector.VerticalWeekMajorItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding FormattedValue}" Margin="0 2" MinWidth="54" TextAlignment="Right" />
            </DataTemplate>
        </telerik:TimeRulerItemTemplateSelector.VerticalWeekMajorItemTemplate>
        <telerik:TimeRulerItemTemplateSelector.VerticalWeekMinorItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding FormattedValue}" Margin="0 2" MinWidth="54" TextAlignment="Right" />
            </DataTemplate>
        </telerik:TimeRulerItemTemplateSelector.VerticalWeekMinorItemTemplate>
        <telerik:TimeRulerItemTemplateSelector.HorizontalTimelineGroupTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding FormattedValue}" Margin="2 1" TextAlignment="Left" />
            </DataTemplate>
        </telerik:TimeRulerItemTemplateSelector.HorizontalTimelineGroupTemplate>
        <telerik:TimeRulerItemTemplateSelector.HorizontalTimelineMajorItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding FormattedValue}" Margin="2" TextAlignment="Left" />
            </DataTemplate>
        </telerik:TimeRulerItemTemplateSelector.HorizontalTimelineMajorItemTemplate>
        <telerik:TimeRulerItemTemplateSelector.HorizontalTimelineMinorItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding FormattedValue}" Margin="2" TextAlignment="Left" />
            </DataTemplate>
        </telerik:TimeRulerItemTemplateSelector.HorizontalTimelineMinorItemTemplate>
        <telerik:TimeRulerItemTemplateSelector.VerticalTimelineGroupTemplate>
            <DataTemplate>
                <telerikPrimitives:LayoutTransformControl VerticalAlignment="Top">
                    <telerikPrimitives:LayoutTransformControl.LayoutTransform>
                        <RotateTransform Angle="-90" />
                    </telerikPrimitives:LayoutTransformControl.LayoutTransform>
                    <TextBlock Text="{Binding FormattedValue}" Margin="2 1" Height="16" TextAlignment="Right" />
                </telerikPrimitives:LayoutTransformControl>
            </DataTemplate>
        </telerik:TimeRulerItemTemplateSelector.VerticalTimelineGroupTemplate>
        <telerik:TimeRulerItemTemplateSelector.VerticalTimelineMajorItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding FormattedValue}" Margin="0 2" MinWidth="54" TextAlignment="Right" />
            </DataTemplate>
        </telerik:TimeRulerItemTemplateSelector.VerticalTimelineMajorItemTemplate>
        <telerik:TimeRulerItemTemplateSelector.VerticalTimelineMinorItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding FormattedValue}" Margin="0 2" MinWidth="54" TextAlignment="Right" />
            </DataTemplate>
        </telerik:TimeRulerItemTemplateSelector.VerticalTimelineMinorItemTemplate>
        <telerik:TimeRulerItemTemplateSelector.MonthGroupTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding FormattedValue}" Margin="6 2" />
            </DataTemplate>
        </telerik:TimeRulerItemTemplateSelector.MonthGroupTemplate>
        <telerik:TimeRulerItemTemplateSelector.MonthItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding FormattedValue}" Margin="6 2" />
            </DataTemplate>
        </telerik:TimeRulerItemTemplateSelector.MonthItemTemplate>
    </telerik:TimeRulerItemTemplateSelector>

    The last template, MonthItemTemplate, is the one you need. Simply replace the binding with any string formatting specifier you wish.

    I hope this helps.

    Regards,
    Dani
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. DevCraft banner
  4. Kjell
    Kjell avatar
    276 posts
    Member since:
    Jun 2010

    Posted 21 Nov 2011 Link to this post

    Thank you, sorry for being dense but can you be more specific with the example.  I tried sticking a formatter in there but it is not working.  For example here is one of the things I tried (I got this from the documentation):

     

    <TextBlock Text="{Binding FormattedValue, StringFormat=d}" Margin="6 2" />

    I know it's the rigth spot because I can wipe the text out but I can't get it to format.  What am I doing wrong?

  5. Dani
    Admin
    Dani avatar
    848 posts

    Posted 22 Nov 2011 Link to this post

    Hi Kjell,

    Please, accept my apologies for the misguiding information. Actually, the DateTime value in the MonthItemTemplate is already formatted and you would use the template selector for customization purposes only.

    To format the DateTime value, you should use a property of the MonthView definition called TimerulerMajorTickStringFormat. Please, consider the following example:

    <telerik:MonthViewDefinition TimerulerMajorTickStringFormat="{}{0:%d}" />

    I hope this helps.

    Kind regards,
    Dani
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  6. Kjell
    Kjell avatar
    276 posts
    Member since:
    Jun 2010

    Posted 22 Nov 2011 Link to this post

    Worked perfectly, thank you.
Back to Top
DevCraft banner