Category / Section
How to disable the weekend dates in the WinUI Date Picker (SfDatePicker) ?
1 min read
In the WinUI CalendarDatePicker, you can disable the weekend dates by using the DataFieldItemPrepared event of the date picker.
XAML
<Window x:Class="CellCustomization.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:CellCustomization" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:calendar="using:Syncfusion.UI.Xaml.Calendar" xmlns:editors="using:Syncfusion.UI.Xaml.Editors"> <editors:SfDatePicker x:Name="sfDatePicker" DateFieldItemPrepared = "SfDatePicker_DateFieldItemPrepared"/> </Window>
C#
By using the DataFieldItemPrepared event and using the DataFieldItemPreparedEventArgs.ItemInfo.IsEnabled property value as `false` for disabling the weekends.
private void SfDatePicker_DateFieldItemPrepared(object sender, DateTimeFieldItemPreparedEventArgs e) { //Restrict the weekend days if (e.ItemInfo.DateTime.Value.DayOfWeek == DayOfWeek.Saturday || e.ItemInfo.DateTime.Value.DayOfWeek == DayOfWeek.Sunday) { e.ItemInfo.IsEnabled = false; } }