How to use WPF SfSchedule commands?
Schedule commands
You can use SfSchedule commands instead of Context Menu to perform the same operation. This article explains how to use the SfSchedule commands in the Schedule. The following Context Menu operations can be handled by using the SfSchedule commands.
1. Adding a new appointment
2. Editing appointments
3. Copy and Paste appointments
4. Deleting appointments
5. DragAndDrop
Using SfSchedule Commands
1. Create a WPF application and add the SfSchedule control to it. Now create Buttons to perform commands in the click event as in the following code example.
XAML
<Window.Resources> <Style TargetType="Button" > <Setter Property="Margin" Value="5"></Setter> <Setter Property="Background" Value="LightSlateGray"></Setter> <Setter Property="HorizontalAlignment" Value="Center"></Setter> <Setter Property="Width" Value="150"></Setter> <Setter Property="FontSize" Value="20"></Setter> </Style> </Window.Resources> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*"></RowDefinition> <RowDefinition Height="0.1*"></RowDefinition> </Grid.RowDefinitions> <syncfusion:SfSchedule ScheduleType="Month" x:Name="schedule"></syncfusion:SfSchedule> <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center"> <Button Content="Add" Name="add" Click="add_Click"></Button> <Button Content="Edit" Name="edit" Click="edit_Click"></Button> <Button Content="Delete" Name="delete" Click="delete_Click" ></Button> <Button Content="Copy" Name="copy" Click="copy_Click"></Button> <Button Content="Paste" Name="paste" Click="paste_Click_1" ></Button> <Button Content="DragAndDrop" Name="drag_drop" Click="drag_drop_Click"></Button> </StackPanel> </Grid>
2. Now add the SfSchedule commands in the click event as follows.
C#
private void add_Click(object sender, RoutedEventArgs e) { ScheduleCommands.AddNewCommand.Execute(this.schedule); } private void edit_Click(object sender, RoutedEventArgs e) { ScheduleCommands.EditCommand.Execute(this.schedule); } private void copy_Click(object sender, RoutedEventArgs e) { ScheduleCommands.CopyCommand.Execute(this.schedule); } private void paste_Click_1(object sender, RoutedEventArgs e) { ScheduleCommands.PasteCommand.Execute(this.schedule); } private void delete_Click(object sender, RoutedEventArgs e) { ScheduleCommands.DeleteCommand.Execute(this.schedule); } private void drag_drop_Click(object sender, RoutedEventArgs e) { ScheduleCommands.DragAndDropCommand.Execute(this.schedule); }
The following screenshots display the different SfSchedule command operations.
1. Adding a new appointment
Click the Add button to add appointments in the Schedule.
Figure 1: Adding new appointment using Add button
Figure 2: Appointment created using Add button
2. Editing Appointments
For editing the appointments, select any of the appointments in the Schedule and click the Edit button.
Figure 3: Editing appointments using Edit button
3. Copy and Paste Appointments
To copy appointments, select any of the appointments in the Schedule and click the Copy button. Then paste the appointment in Schedule using the Paste button.
Figure 4: Copy and Paste Appointments
4. Deleting Appointments
For deleting appointments, select any of the appointments in Schedule and click the Delete button.
Figure 5: Deleting appointments using Delete button
5. DragAndDrop
For doing DragAndDrop, select any of the appointments in the Schedule and click the DragAndDrop button.
Figure 6: Drag and Drop the appointments