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

DateTime StringFormat in TimeRuler

5 Answers 146 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Jesus
Top achievements
Rank 1
Jesus asked on 22 May 2013, 05:36 PM
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

5 Answers, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 27 May 2013, 12:54 PM
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.

0
Jesus
Top achievements
Rank 1
answered on 27 May 2013, 03:35 PM

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


















0
Vladi
Telerik team
answered on 29 May 2013, 02:31 PM
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.

0
Jesus
Top achievements
Rank 1
answered on 29 May 2013, 04:31 PM
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












0
Vladi
Telerik team
answered on 31 May 2013, 02:37 PM
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.

Tags
ScheduleView
Asked by
Jesus
Top achievements
Rank 1
Answers by
Vladi
Telerik team
Jesus
Top achievements
Rank 1
Share this question
or