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

Customize RadDatePicker (Silverlight)

10 Answers 421 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Mark Owen
Top achievements
Rank 1
Mark Owen asked on 03 Mar 2009, 09:16 PM
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

10 Answers, 1 is accepted

Sort by
0
Miroslav
Telerik team
answered on 04 Mar 2009, 08:48 AM
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.
0
Mark Owen
Top achievements
Rank 1
answered on 04 Mar 2009, 04:27 PM
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
0
jlnovo
Top achievements
Rank 1
answered on 06 Aug 2010, 11:44 PM
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.
0
George
Telerik team
answered on 10 Aug 2010, 08:59 AM
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
0
Adam
Top achievements
Rank 1
answered on 01 Apr 2011, 09:57 PM
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?
0
Yana
Telerik team
answered on 07 Apr 2011, 01:56 PM
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
0
Sébastien
Top achievements
Rank 1
answered on 25 Apr 2012, 07:27 PM
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?
0
Yana
Telerik team
answered on 27 Apr 2012, 12:36 PM
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 >>

0
Sébastien
Top achievements
Rank 1
answered on 27 Apr 2012, 02:49 PM
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; }
    }
0
Yana
Telerik team
answered on 02 May 2012, 09:38 AM
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 >>

Tags
DatePicker
Asked by
Mark Owen
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
Mark Owen
Top achievements
Rank 1
jlnovo
Top achievements
Rank 1
George
Telerik team
Adam
Top achievements
Rank 1
Yana
Telerik team
Sébastien
Top achievements
Rank 1
Share this question
or