Hi,
I need to disable the Weekends and Holidays while selecting the date.In order to achieve this I tried using following code.
I need to disable the Weekends and Holidays while selecting the date.In order to achieve this I tried using following code.
<
telerik:RadDatePicker
Width
=
"150"
Margin
=
"8 5"
DateSelectionMode
=
"Day"
Name
=
"dtFirstPHDate"
SelectedValue
=
"{Binding mFirstPHDate, Mode=TwoWay}"
>
<
telerik:RadDatePicker.DayTemplateSelector
>
<
DateTemplate:CustomTemplateSelector
>
<
DateTemplate:CustomTemplateSelector.DefaultTemplate
>
<
DataTemplate
>
<
TextBlock
Text
=
"{Binding dtStartDate, Mode=TwoWay}"
></
TextBlock
>
</
DataTemplate
>
</
DateTemplate:CustomTemplateSelector.DefaultTemplate
>
</
DateTemplate:CustomTemplateSelector
>
</
telerik:RadDatePicker.DayTemplateSelector
>
</
telerik:RadDatePicker
>
public class CustomTemplateSelector : DataTemplateSelector
{
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
CalendarButtonContent content = item as CalendarButtonContent;
if (content != null)
{
if (content.Date.DayOfWeek == DayOfWeek.Saturday || content.Date.DayOfWeek == DayOfWeek.Sunday||holidaysList.Contains(content.Date))
{
content.IsEnabled = false;
}
}
return DefaultTemplate;
}
public DataTemplate DefaultTemplate
{
get;
set;
}
}
But still it is not working.
FYI
DateTime Picker Version:2010.2.0714.1040 (RadControls for Silverlight Q2 2010).Please help me to resolve this issue.
11 Answers, 1 is accepted
0
Hi Deepak,
George
the Telerik team
I would suggest you to refer to the following forum thread - http://www.telerik.com/community/forums/silverlight/datepicker/daytemplateselector.aspx
I hope this helps.
George
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Deepak
Top achievements
Rank 1
answered on 03 Dec 2010, 06:55 PM
Hi George ,
Thanks for your Quick reply.
Please find my comments below
<
telerik:RadDatePicker
x:Name
=
"radDatePicker"
HorizontalAlignment
=
"Center"
VerticalAlignment
=
"Center"
>
<
telerik:RadDatePicker.CalendarStyle
>
<
Style
TargetType
=
"telerik:RadCalendar"
>
<
Setter
Property
=
"DayTemplate"
Value
=
"{x:Null}"
/>
<
Setter
Property
=
"DayTemplateSelector"
>
<!--your implementation here-->
<!--How can add Weekdays and Holidays here-->
<!--I had overridden DataTemplateSelector with the Class name CustomTemplateSelector-->
<!--class file "CustomTemplateSelector" code is mentioned below -->
</
Setter
>
</
Style
>
</
telerik:RadDatePicker.CalendarStyle
>
</
telerik:RadDatePicker
>
public class CustomTemplateSelector : DataTemplateSelector
{
public static ObservableCollection<
DateTime
> holidaysList = new ObservableCollection<
DateTime
>();
PHPMDatesSchedular.SchedulerClient holidaysClient = new PHPMDatesSchedular.SchedulerClient();
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
holidaysClient.GetHolidaysAsync();
holidaysClient.GetHolidaysCompleted += new EventHandler<
GetHolidaysCompletedEventArgs
>(holidaysClient_GetHolidaysCompleted);
CalendarButtonContent content = item as CalendarButtonContent;
if (content != null)
{
if (content.Date.DayOfWeek == DayOfWeek.Saturday || content.Date.DayOfWeek == DayOfWeek.Sunday || holidaysList.Contains(content.Date))
{
content.IsEnabled = false;
}
}
return DefaultTemplate;
}
void holidaysClient_GetHolidaysCompleted(object sender, GetHolidaysCompletedEventArgs e)
{
holidaysList = e.holidays;
}
public DataTemplate DefaultTemplate
{
get;
set;
}
}
0
Hi Deepak,
Your code should look similar to the following one:
Let us know if you are still experiencing a problem.
Regards,
Kaloyan
the Telerik team
Your code should look similar to the following one:
<
Setter
Property
=
"DayTemplateSelector"
>
<
Setter.Value
>
<
local:CustomTemplateSelector
>
<
local:CustomTemplateSelector.DefaultTemplate
>
<
DataTemplate
>
<
TextBlock
Text
=
"{Binding Text}"
Foreground
=
"Red"
/>
</
DataTemplate
>
</
local:CustomTemplateSelector.DefaultTemplate
>
</
local:CustomTemplateSelector
>
</
Setter.Value
>
</
Setter
>
Let us know if you are still experiencing a problem.
Regards,
Kaloyan
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Lim
Top achievements
Rank 1
answered on 26 Feb 2014, 03:32 AM
Hi,
I have download your sample and used the telerik.windows.controls.input dll of version 2013.3.1316.1050. And noticed problems when swithing from febuary to march and other months. the dates picked is totally off compared to the values in the date picker text box.
I removed the daytemplate selector and it works properly just that the weekends are now reselectable. So i figured the custom template selector is causing problems
I have download your sample and used the telerik.windows.controls.input dll of version 2013.3.1316.1050. And noticed problems when swithing from febuary to march and other months. the dates picked is totally off compared to the values in the date picker text box.
I removed the daytemplate selector and it works properly just that the weekends are now reselectable. So i figured the custom template selector is causing problems
0
Hi Lim,
We are not aware of such problems. I've tried to reproduce the problem you've mentioned, but unfortunately I couldn't. Please check the attached sample project which demonstrates how to disable the weekends and the holidays.
If you have any other issues considering this case, please don't hesitate to contact us again.
Regards,
Ventzi
Telerik
We are not aware of such problems. I've tried to reproduce the problem you've mentioned, but unfortunately I couldn't. Please check the attached sample project which demonstrates how to disable the weekends and the holidays.
If you have any other issues considering this case, please don't hesitate to contact us again.
Regards,
Ventzi
Telerik
0
Lim
Top achievements
Rank 1
answered on 27 Feb 2014, 12:34 AM
Hi, is there anyway for me to attach you my sample with the error?
0
Lim
Top achievements
Rank 1
answered on 27 Feb 2014, 12:50 AM
Hi, Please look at the image i attached. it shows you the error.
Also could you please give me a silverlight sample?
Thanks
Cheers,
Shang Yi
Also could you please give me a silverlight sample?
Thanks
Cheers,
Shang Yi
0
Hello Lim,
I've created a Silverlight version of the sample project which you could find attached.
In our forum are allowed only images for security reasons. If you like to attach a sample project you need to register and then to open a support ticket. You could find more about our support plans here.
Regards,
Ventzi
Telerik
I've created a Silverlight version of the sample project which you could find attached.
In our forum are allowed only images for security reasons. If you like to attach a sample project you need to register and then to open a support ticket. You could find more about our support plans here.
Regards,
Ventzi
Telerik
0
Lim
Top achievements
Rank 1
answered on 27 Feb 2014, 03:23 PM
did you look at the image i have attached? Are you able to replicate the issue with the image?
0
Lim
Top achievements
Rank 1
answered on 28 Feb 2014, 02:32 AM
Hi I am able to fix it using the sample provided.
However, it couldnt work with the approach posted here:
http://www.telerik.com/forums/disable-all-weekdays-and-all-weekends
Have you guys included documentation on disabling weekdays? it would be best to include it there so we can always refer to the updated document.
However, it couldnt work with the approach posted here:
http://www.telerik.com/forums/disable-all-weekdays-and-all-weekends
Have you guys included documentation on disabling weekdays? it would be best to include it there so we can always refer to the updated document.
0
Hello Lim,
If you need to disable the weekends in addition to solution Ventzi has provided you - you will need to add the following if statement in the begging of the SelectTemplate method:
Thanks for the feedback about the documentation, we will consider including article about the TemplateSelectors in the Calendar of the DateTimePicker. You can also check the BlackoutDates article which demonstrate how to disable particular dates from the DateTimePicker calendar.
Hope this helps.
Regards,
Kalin
Telerik
If you need to disable the weekends in addition to solution Ventzi has provided you - you will need to add the following if statement in the begging of the SelectTemplate method:
public
override
System.Windows.DataTemplate SelectTemplate(
object
item, System.Windows.DependencyObject container)
{
var content = item
as
CalendarButtonContent;
if
((content.Date.DayOfWeek == DayOfWeek.Saturday || content.Date.DayOfWeek == DayOfWeek.Sunday) && content.ButtonType == CalendarButtonType.Date)
{
content.IsEnabled =
false
;
}
....
}
Thanks for the feedback about the documentation, we will consider including article about the TemplateSelectors in the Calendar of the DateTimePicker. You can also check the BlackoutDates article which demonstrate how to disable particular dates from the DateTimePicker calendar.
Hope this helps.
Regards,
Kalin
Telerik