How to add the blackout dates in the WinUI Calendar (SfCalendar)
In the WinUI Calendar (SfCalendar), add the particular dates as blackout dates by using the BlackoutDates property which is used to restrict the interaction on the particular calendar dates.
CS
Create a ViewModel class and add the required dates as blackout dates.
public class ViewModel
{
public DateTimeOffsetCollection BlockedDates { get; set; }
public ViewModel()
{
BlockedDates = new DateTimeOffsetCollection();
BlockedDates.Add(new DateTimeOffset(new DateTime(2021, 1, 17)));
BlockedDates.Add(new DateTimeOffset(new DateTime(2021, 1, 4)));
BlockedDates.Add(new DateTimeOffset(new DateTime(2021, 2, 5)));
BlockedDates.Add(new DateTimeOffset(new DateTime(2021, 2, 6)));
BlockedDates.Add(new DateTimeOffset(new DateTime(2021, 1, 9)));
BlockedDates.Add(new DateTimeOffset(new DateTime(2021, 3, 11)));
BlockedDates.Add(new DateTimeOffset(new DateTime(2021, 1, 13)));
BlockedDates.Add(new DateTimeOffset(new DateTime(2021, 4, 14)));
BlockedDates.Add(new DateTimeOffset(new DateTime(2021, 1, 18)));
BlockedDates.Add(new DateTimeOffset(new DateTime(2021, 5, 19)));
BlockedDates.Add(new DateTimeOffset(new DateTime(2021, 1, 26)));
BlockedDates.Add(new DateTimeOffset(new DateTime(2021, 6, 29)));
BlockedDates.Add(new DateTimeOffset(new DateTime(2021, 1, 31)));
BlockedDates.Add(new DateTimeOffset(new DateTime(2021, 1, 27)));
}
}
XAML
Bind those BlockedDates property from the ViewModel by setting the DataContext, to BlackoutDates property of the calendar.
<xmlns:calendar="using:Syncfusion.UI.Xaml.Calendar">
<calendar:SfCalendar x:Name="sfCalendar"
BlackoutDates="{Binding BlockedDates}">
<calendar:SfCalendar.DataContext>
<local:ViewModel/>
</calendar:SfCalendar.DataContext>
</calendar:SfCalendar>
