Category / Section
How to show a particular week in a day view of WinUI Scheduler (Calendar)
1 min read
Restrict the day view for the selected week only, by using the MinimumDate and the MaximumDate properties of the WinUI SfScheduler.
XAML
Set the FirstDayOfWeek as Monday and the ViewType as Week.
<Grid> <Grid.RowDefinitions> <RowDefinition Height="50"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <StackPanel Orientation="Horizontal" Spacing="10" Padding="10" HorizontalAlignment="Right" Grid.Row="0"> <Button Content="Day" Width="100" x:Name="DayButton" Click="OnDayButtonClicked"/> <Button Content="Week" Width="100" x:Name="WeekButton" Click="OnWeekButtonClicked"/> </StackPanel> <scheduler:SfScheduler x:Name="scheduler" Grid.Row="1" FirstDayOfWeek="Monday" ViewType="Week" ViewChanged="OnSchedulerViewChanged"> </scheduler:SfScheduler> </Grid>
C#
Get the week’s first and last date by using the ViewChangedEventArgs argument of the ViewChanged event. Using this, set the MinimumDate and the MaximumDate for the schedule while navigating to day view. Also, change the min/max value while navigating back to week view.
public sealed partial class MainPage : Page { DateTime minDate, maxDate; public MainPage() { this.InitializeComponent(); scheduler.DisplayDate = DateTime.Now.Date.AddHours(9); } private void OnDayButtonClicked(object sender, RoutedEventArgs e) { this.scheduler.MinimumDate = minDate; this.scheduler.MaximumDate = maxDate; this.scheduler.ViewType = SchedulerViewType.Day; } private void OnWeekButtonClicked(object sender, RoutedEventArgs e) { this.scheduler.ViewType = SchedulerViewType.Week; } private void OnSchedulerViewChanged(object sender, Syncfusion.UI.Xaml.Scheduler.ViewChangedEventArgs e) { if (this.scheduler.ViewType == SchedulerViewType.Week) { minDate = e.NewValue.ActualStartDate; maxDate = e.NewValue.ActualEndDate; this.scheduler.MinimumDate = new DateTime(01, 01, 01); this.scheduler.MaximumDate = new DateTime(9999, 12, 31); } } }