Customize RadDatePicker (Silverlight)

11 posts, 0 answers
  1. Mark Owen
    Mark Owen avatar
    2 posts
    Member since:
    Sep 2008

    Posted 03 Mar 2009 Link to this post

    I would like to limit the dates available on the dropdown to only show Saturday's as available to select. The RadCalendar has an example that does this already: the RadCalendar sets the template for the DayTemplateSelector and uses a custom class to check the dates. This does not work on the RadDatePicker. I am unable to get this same logic to work on the RadDatePicker. Can I get an example of how to do this?

    thanks, Mark
  2. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 04 Mar 2009 Link to this post

    Hi Mark,

    The Calendar and DatePicker have an almost identical API and functionality. I managed to disable all dates but saturdays, very similarly to the Calendar example.

    There is a default DayTemplate for the DatePicker that takes precedence over the DayTemplateSelector and therefore needs to be set to null. This may be the reason why it was not working in your case.

    You can have a look at the attached example with a DatePicker with disabled days.

    I hope that this works for you,

    Regards,
    Miroslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. Mark Owen
    Mark Owen avatar
    2 posts
    Member since:
    Sep 2008

    Posted 04 Mar 2009 Link to this post

    Miroslav,
    Thanks for the response - that fixed it. I left out the DayTemplate="{x:Null}" property in my code, therefore it wasn't accessing the custom class, the code worked as soon as I added it. Thanks again.

    Mark
  5. jlnovo
    jlnovo avatar
    4 posts
    Member since:
    Oct 2006

    Posted 06 Aug 2010 Link to this post

    Hi Miroslav,

    It is a very good example the one that you gave. But I was wondering, how can I disable special dates, like hollydays, in the same way you did it with the days that are not saturday.

    I have a collection with dates that i wouldn't like the user to be able to select them, how could disable them in the datepicker? The collection I mentioned is set in the constructor of the view of the calendar...

    Hope you can help.

    Greetings.
  6. George
    Admin
    George avatar
    1332 posts

    Posted 10 Aug 2010 Link to this post

    Hi jlnovo,

    Thank you for contacting us.

    Attached you can find the sample that illustrate how to disable days according to a DateTime collection.

    I hope this helps. 

    Kind regards,
    George
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Adam
    Adam avatar
    19 posts
    Member since:
    Apr 2011

    Posted 01 Apr 2011 Link to this post

    How do you make it so the radDatePicker only has enabled certain days, according to a list that you get at runtime?

    In other words, how do I supply the radDatePicker with a list of Dates that I want to be enabled, and disable all the other days, so the user can only select certain days?
  8. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 07 Apr 2011 Link to this post

    Hello jlnovo,

    You should still use DataTemplateSelector to disable certain days. Note that the template of RadDatePicker should be reset in order to apply the changes in the view, this can be done like this:

    radTimePicker.Template = null;
    radTimePicker.SetValue(RadDateTimePicker.TemplateProperty, DependencyProperty.UnsetValue);

    the provided code will fire SelectTemplate method of the selector. 
    You can find my test project attached. Hope it helps.

    Regards,
    Yana
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Sébastien
    Sébastien avatar
    17 posts
    Member since:
    Mar 2011

    Posted 25 Apr 2012 Link to this post

    Hello Telerik,

    Is it possible that the latest internal build (April 23rd 2012 ) removed the daytemplateselector property from the raddatepicker ? We used to be able to select only sunday in a raddatepicker prior to install the latest internal build and now this feature is not working anymore.

    Can you assist?
  10. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 27 Apr 2012 Link to this post

    Hi Sébastien,

    We've tested the project with the latest internal build and there were no problems. Please send us more details about the issue you're experiencing. Thanks

    Greetings,
    Yana
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  11. Sébastien
    Sébastien avatar
    17 posts
    Member since:
    Mar 2011

    Posted 27 Apr 2012 Link to this post

    Hello again,

    Here's some code sample from what we are trying to do.

    We are using the RadDatePicker but we set it for displaying only sunday.

    Somehow this feature using the following code is not working anymore.

    Is it because the RadCalendar and RadDatePicker are not compatible anymore, if so how should I use the style to target RadDatePicker?

    Regards

    <!-- XAML CALL With calendar style property -->
      
    <telerik:RadDatePicker Name="leCalendrier" Width="200" DateTimeWatermarkContent="Sélectionnez un dimanche" DisplayFormat="Long" 
                                           SelectionChanged="leCalendrier_SelectionChanged" CalendarStyle="{StaticResource RadCalendarSeulDimancheStyle}"/>
      
    <!-- STYLE -->
    <Style x:Key="RadCalendarSeulDimancheStyle" TargetType="telerik:RadCalendar" >
            <Setter Property="DayTemplateSelector">
                <Setter.Value>
                    <helper:SeulDimanchePossible>
                        <helper:SeulDimanchePossible.DefaultTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Text}" />
                            </DataTemplate>
                        </helper:SeulDimanchePossible.DefaultTemplate>
                    </helper:SeulDimanchePossible>
                </Setter.Value>
            </Setter>
        </Style>
      
      
    <!-- helper -->
      
    public class SeulDimanchePossible : Telerik.Windows.Controls.DataTemplateSelector
        {
            public override DataTemplate SelectTemplate(object item, DependencyObject container)
            {
                Telerik.Windows.Controls.Calendar.CalendarButtonContent content = item as Telerik.Windows.Controls.Calendar.CalendarButtonContent;
      
                if (content != null)
                {
                    if (content.Date.DayOfWeek != DayOfWeek.Sunday && 
                        (content.ButtonType == Telerik.Windows.Controls.Calendar.CalendarButtonType.Date
                        || content.ButtonType == Telerik.Windows.Controls.Calendar.CalendarButtonType.TodayDate))
                    {
                        content.IsEnabled = false;
                    }
                }
      
                return DefaultTemplate;
            }
      
            public DataTemplate DefaultTemplate { get; set; }
        }
  12. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 02 May 2012 Link to this post

    Hi Sébastien,

    I've tested the provided code and it works as expected at our side, Ive attached my test project for a reference.
    Please download and give it a try.

    All the best,
    Yana
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
DevCraft banner