SfScheduler DisabledDateBackground not work

SfScheduler View="Month"

I have set MinimumDateTime with only DisabledDateTextStyle as work DisabledDateBackground not work


1 Reply

VM Vidyalakshmi Mani Syncfusion Team April 16, 2024 12:46 PM UTC

Hi Bao,


Thank you for reaching out to us. We have investigated your query regarding the DisabledDateBackground in the MonthView. As per the implementation, the DisabledDateBackground is not applicable to the MonthView. This information is also outlined in our User Guide documentation here. However, you can achieve the desired outcome by customizing the appearance of the dates in the Month view using the CellTemplate and a converter.


Here’s a code snippet for your reference:


MainPage.xaml


 

<ContentPage.Resources>

     <local:BackgroundColorConverter x:Key="BGColorConverter" />

     <local:TextColorConverter x:Key="TextColorConverter"/>

 </ContentPage.Resources>

 

 <scheduler:SfScheduler x:Name="Scheduler"

                        View="Week"

                        DisplayDate="{Binding DisplayDate}"

                        AppointmentsSource="{Binding Events}"

                        AllowedViews="Day,Week,WorkWeek,Month,TimelineDay,TimelineWeek,TimelineWorkWeek,TimelineMonth">

       

     <scheduler:SfScheduler.MonthView>

         <scheduler:SchedulerMonthView>

             <scheduler:SchedulerMonthView.CellTemplate>

                 <DataTemplate>

                     <Grid  Background = "{Binding DateTime.Date, Converter = {StaticResource BGColorConverter}}">

                            <Label HorizontalTextAlignment="Center" TextColor="{Binding DateTime.Date, Converter = {StaticResource TextColorConverter}}" Text="{Binding DateTime.Day}"/>

                     </Grid>

                 </DataTemplate>

             </scheduler:SchedulerMonthView.CellTemplate>

         </scheduler:SchedulerMonthView>

     </scheduler:SfScheduler.MonthView>

       

     <scheduler:SfScheduler.BindingContext>

         <local:SchedulerViewModel />

     </scheduler:SfScheduler.BindingContext>

       

 </scheduler:SfScheduler>

 


Converter class:


 

public class BackgroundColorConverter : IValueConverter

{

    DateTime minimumDate = DateTime.Today.AddMonths(-1).AddHours(9);

 

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)

    {

        if (value is DateTime date)

        {

            return date.Date < minimumDate? Brush.LightSkyBlue : Brush.White;

        }

 

        return Brush.White;

    }

 

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

    {

        throw new NotImplementedException();

    }

}

 


In the converter, you can check if the date is disabled and return the appropriate background color. We have also created a sample to illustrate this approach, which you can find attached for your reference.


Please let us know if you need any further assistance or have any other questions.


Regards,

Vidyalakshmi M.



Attachment: GettingStarted_bdfd73eb.zip

Loader.
Up arrow icon