DateTime StringFormat in TimeRuler

6 posts, 0 answers
  1. Jesus
    Jesus avatar
    9 posts
    Member since:
    Feb 2012

    Posted 22 May 2013 Link to this post

    Hi there!!..

    I´m trying to change the Format Date is shown in TmeRuler weekview...

    I have an OrientedGroupHeaderContentTemplateselector, inside i have an HorizontalDayViewDateTemplate, which contains a DataTemplate with a TextBlock like this:

    <TextBlock Margin="4" Text="{Binding Name, StringFormat=dd dddd}"/>


    But I change this to:

    <TextBlock Margin="0" Text="{Binding Name, StringFormat=d, Converter={StaticResource StringFormatConverter}, ConverterParameter='\{0:d\}'}" />


    where StringFormatConverter is this:

    public class stringFormatConverter:IValueConverter

    {

    #region IValueConverter Members

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

    {

    string res = String.Empty;

    if (parameter != null)

    {

    string formatString = parameter.ToString();

    if (!string.IsNullOrEmpty(formatString))

    {

    res= String.Format(formatString, value);

    return res;

    }

    }

    return value.ToString();

    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

    {

    return value;

    }

    #endregion

    }

    The problem I have, is I like to change the format to {0:ddd d} to show "Fri 29" instead "Friday 29", but the application sends an error if I don´t set {0:d} in the textblock ConvertParameter.

    "Línea: 1 Error: Unhandled Error in Silverlight Application Se detectó un ciclo de diseño. No se pudo completar el diseño."

    The class StringFormatConverter Formats successful the Date, but the Schedule don't work.


    Any ideas, how could work.....?

    Saludos
    José de Jesús

  2. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 27 May 2013 Link to this post

    Hello,

    If the desired behavior is to change the default date format in WeekView from "Friday 29" to "Fri 29" all you need to do is set the GroupHeaderDateStringFormat of the WeekViewDefinition to the desired format.

    The next code snippet shows how to achieve the desired format:
    <telerik:RadScheduleView>
        <telerik:RadScheduleView.ViewDefinitions>
            <telerik:WeekViewDefinition GroupHeaderDateStringFormat="{}{0:ddd d}"/>
        </telerik:RadScheduleView.ViewDefinitions>
    </telerik:RadScheduleView>

    Hope this is helpful.

    Regards,
    Vladi
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Jesus
    Jesus avatar
    9 posts
    Member since:
    Feb 2012

    Posted 27 May 2013 Link to this post

    I add  GroupHeaderDateStringFormat="{}{0:ddd d}" property but the time String format doesnt change.

    This is my code:

    <telerik:RadScheduleView x:Name="scheduler" HorizontalAlignment="Left" VerticalAlignment="Top" Height="822" Width="950" 
                                     FirstVisibleTime="8:0:0" ShowCurrentTimeIndicator="True" ActiveViewDefinitionIndex="1"
                                     Margin="10,56,0,0"
                                     GroupHeaderContentTemplateSelector="{StaticResource GroupHeaderContentTemplateSelector}"                                
                                     ToolTipTemplate="{StaticResource AppointmentToolTipTemplate}"
                                     Background="White" Style="{StaticResource RadScheduleViewStyle1}"
                                     ShowDialog="scheduler_ShowDialog"
                                     MinAppointmentWidth="1"                                
                                    >                 
                                                  
                <telerik:RadScheduleView.ViewDefinitions>
                    <telerik:DayViewDefinition/>
                    <telerik:WeekViewDefinition DayStartTime="08:00:00" DayEndTime="20:00:00" MinTimeRulerExtent="1" MinorTickLength="1h" LargeChangeInterval="7d" StretchGroupHeaders="False" GroupHeaderDateStringFormat="{}{0:ddd d}"/>                                                   
                    <telerik:MonthViewDefinition/>
                    <telerik:TimelineViewDefinition/>
                </telerik:RadScheduleView.ViewDefinitions>           
    </telerik:RadScheduleView>
     
     
    <local:OrientedGroupHeaderContentTemplateSelector x:Key="GroupHeaderContentTemplateSelector">
                <!-- Default templates: -->           
                <local:OrientedGroupHeaderContentTemplateSelector.HorizontalDayViewDateTemplate>
                    <DataTemplate>
                        <!--<TextBlock Margin="0 0 0 0" Text="{Binding Name, StringFormat=d ddd, Converter={StaticResource StringFormatConverter}, ConverterParameter='\{0:d\}'}" />-->
                        <TextBlock Margin="4" Text="{Binding Name, StringFormat=dd dddd}"/>
                    </DataTemplate>
                </local:OrientedGroupHeaderContentTemplateSelector.HorizontalDayViewDateTemplate>
    </local:OrientedGroupHeaderContentTemplateSelector>



    Any other solution?
    Txs.

    José de Jesús


















  5. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 29 May 2013 Link to this post

    Hi,

    Setting both GroupHeaderDateStringFormat to the ViewDefiniton and creating custom GroupHeaderContentTemplateSelector  is not supported because the TemplateSelector overrides the GroupHeaderDateStringFormat property. You should either use the GroupHeaderDateStringFormat property or when creating custom selector set a correct StringFormat to the TextBlock that represents the date.

    The next code snippet works as expected on our side:
    <telerik:RadScheduleView>
        <telerik:RadScheduleView.ViewDefinitions>
            <telerik:WeekViewDefinition GroupHeaderDateStringFormat="{}{0:ddd d}"/>
        </telerik:RadScheduleView.ViewDefinitions>
    </telerik:RadScheduleView>


    Regards,
    Vladi
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Jesus
    Jesus avatar
    9 posts
    Member since:
    Feb 2012

    Posted 29 May 2013 Link to this post

    I set this:

    <local:OrientedGroupHeaderContentTemplateSelector.HorizontalDayViewDateTemplate>
                    <DataTemplate>                  
                        <TextBlock Margin="1" Text="{Binding Name, StringFormat='\{0:ddd d MM\}'}" />                   
                    </DataTemplate>
                </local:OrientedGroupHeaderContentTemplateSelector.HorizontalDayViewDateTemplate>

    Is close enoughthat I need, but If change StringFormat to:   StringFormat='\{0:ddd d\} '   Still crashes

    Txs, for the help......

    José de Jesús












  7. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 31 May 2013 Link to this post

    Hello,

    We are not aware of any issues when setting either the GroupHeaderDateStringFormat of the ViewDefinition or the GroupHeaderContentTemplateSelector with custom StringFormat.

    You can find attached to my response a sample project that shows both approaches.

    Regards,
    Vladi
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
DevCraft banner