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

Past Dates Not Visible in RadDatepicker.

1 Answer 118 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Karthick
Top achievements
Rank 1
Karthick asked on 17 Mar 2021, 10:53 AM

Hi,

Im using RadDatepicker for from date and to date, In from date, im using DisplayDateEnd as ValidTo and in to date, im using DisplayDateStart as ValidFrom, its works fine based on the date selection of valid from and valid to, but how can i see the dates which are not visible.

I want to see the dates in calender with disabled mode of past and future dates.

Thanks,

Karthick.

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 22 Mar 2021, 10:02 AM

Hi Karthick,

If I understand your requirement correctly, you want to have the dates which are not inside the ValidFrom to ValidTo interval still appear in the calendar but have a disabled state.

If this is indeed the case, what I can suggest is to use the DayButtonStyleSelector property of the RadCalendar control which is displayed in the RadDatePicker. Here's how you can set it up:

    <Window.Resources>
        <local:DayButtonStyleSelector x:Key="CustomStyleSelector" 
                                      ValidFrom="03/20/2021"
                                      ValidTo="03/27/2021">
            <local:DayButtonStyleSelector.DisabledDatesStyle>
                <Style TargetType="calendar:CalendarButton">
                    <Setter Property="IsHitTestVisible" Value="False" />
                    <Setter Property="Foreground" Value="LightGray" />
                </Style>
            </local:DayButtonStyleSelector.DisabledDatesStyle>
        </local:DayButtonStyleSelector>
        <Style x:Key="CustomCalendarStyle" TargetType="telerik:RadCalendar">
            <Setter Property="DayButtonStyle" Value="{x:Null}" />
            <Setter Property="DayButtonStyleSelector" Value="{StaticResource CustomStyleSelector}" />
        </Style>
    </Window.Resources>

You can then define the logic inside its SelectyStyle method as follows:

        public override Style SelectStyle(object item, DependencyObject container)
        {
            CalendarButtonContent content = item as CalendarButtonContent;
            if (content != null)
            {
                if (content.ButtonType == CalendarButtonType.Date && 
                        (content.Date < this.ValidFrom || content.Date > this.ValidTo))
                {
                    return DisabledDatesStyle;
                }
            }

            return base.SelectStyle(item, container);
        }

For your convenience, I've also prepared a small sample project which demonstrates the approach I have in mind.

Please have a look and let me know if something similar would work for you.

Regards,
Dilyan Traykov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
DatePicker
Asked by
Karthick
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or