How to show a particular week in a day view of WPF Scheduler?
You can restrict the day view for the selected week only by using the MinimumDate and MaximumDate properties of WPF Scheduler .
XAML
Set the FirstDayOfWeek as Monday and ViewType as Week.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="0">
<Button Content="Day" Width="100" x:Name="DayButton"/>
<Button Content="Week" Width="100" x:Name="WeekButton"/>
</StackPanel>
<syncfusion:SfScheduler x:Name="Schedule"
Grid.Row="1"
FirstDayOfWeek="Monday"
ViewType="Week"
ItemsSource="{Binding Meetings}">
<syncfusion:SfScheduler.AppointmentMapping>
<syncfusion:AppointmentMapping StartTime="From"
EndTime="To"
Subject="EventName"
AppointmentBackground="Color"
IsAllDay="IsAllDay"/>
</syncfusion:SfScheduler.AppointmentMapping>
</syncfusion:SfScheduler>
<interactivity:Interaction.Behaviors>
<local:SchedulerBehavior/>
</interactivity:Interaction.Behaviors>
</Grid>
C#
You can get the week’s first and last date by using the ViewChangedEventArgs argument of ViewChanged event, using this you can set the MinimumDate and MaximumDate for schedule while navigating to day view. Also, changing the min/max value while navigating back to week view.
public class SchedulerBehavior : Behavior<Grid>
{
SfScheduler scheduler;
Button dayButton, weekButton;
private DateTime minDate, maxDate;
protected override void OnAttached()
{
base.OnAttached();
scheduler = this.AssociatedObject.FindName("Schedule") as SfScheduler;
dayButton = this.AssociatedObject.FindName("DayButton") as Button;
weekButton = this.AssociatedObject.FindName("WeekButton") as Button;
scheduler.DisplayDate = DateTime.Now.Date.AddHours(9);
this.OnWirEvents();
}
private void OnWirEvents()
{
this.dayButton.Click += DayButton_Click;
this.weekButton.Click += WeekButton_Click;
this.scheduler.ViewChanged += Scheduler_ViewChanged;
}
private void Scheduler_ViewChanged(object sender, 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);
}
}
private void WeekButton_Click(object sender, RoutedEventArgs e)
{
this.scheduler.ViewType = SchedulerViewType.Week;
}
private void DayButton_Click(object sender, RoutedEventArgs e)
{
this.scheduler.MinimumDate = minDate;
this.scheduler.MaximumDate = maxDate;
this.scheduler.ViewType = SchedulerViewType.Day;
}
protected override void OnDetaching()
{
base.OnDetaching();
this.UnWireEvents();
this.scheduler = null;
this.dayButton = null;
this.weekButton = null;
}
private void UnWireEvents()
{
this.dayButton.Click -= DayButton_Click;
this.weekButton.Click -= WeekButton_Click;
this.scheduler.ViewChanged -= Scheduler_ViewChanged;
}
}
Conclusion
Hope you enjoyed learning about how to show a particular week in a day view of WPF Scheduler.
You can refer to our WPF Scheduler feature tour page to learn about its other groundbreaking feature representations. You can explore our WPF Scheduler documentation to understand how to present and manipulate data.
For current customers, you can check out our Angular components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our Angular Diagram and other Angular components.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!