How to add delete icon to each appointment of the WPF Scheduler (Calendar)
In the WPF Scheduler, you can add the delete icon and remove the particular appointment by using that icon in the AppointmentTemplate.
XAML
Use the DataTemplate for the appointments and bind appointments to corresponding property.
<DataTemplate x:Key="appointmentTemplate"> <Grid Background="{Binding Background}" HorizontalAlignment="Stretch"> <Grid.RowDefinitions> <RowDefinition Height="0.5*"/> <RowDefinition Height="0.5*"/> </Grid.RowDefinitions> <StackPanel HorizontalAlignment="Stretch"> <Button x:Name="button" Grid.Row="0" Style="{StaticResource ButtonStyle1}" Background="{Binding Background}" HorizontalContentAlignment="Stretch"> <Image x:Name="Image" HorizontalAlignment="Right" VerticalAlignment="Top" Height="30" Width="15" Margin="5,0,0,0" Source="close-window.png"> <interactivity:Interaction.Triggers> <interactivity:EventTrigger EventName="Loaded"> <local:ScheduleBehavior TargetObject="{Binding ElementName=Schedule}"/> </interactivity:EventTrigger> </interactivity:Interaction.Triggers> </Image> </Button> </StackPanel> <TextBlock Margin="5" Grid.Row="1" VerticalAlignment="Center" Text="{Binding EventName}" TextTrimming="CharacterEllipsis" TextWrapping="Wrap" TextAlignment="Left" FontWeight="Bold"/> </Grid> </DataTemplate> <syncfusion:SfScheduler x:Name="Schedule" ViewType="{Binding ElementName=viewTypeComboBox, Path=SelectedValue}" ItemsSource="{Binding Appointments}"> <syncfusion:SfScheduler.DaysViewSettings> <syncfusion:DaysViewSettings AppointmentTemplate="{StaticResource appointmentTemplate}"/> </syncfusion:SfScheduler.DaysViewSettings> <syncfusion:SfScheduler.TimelineViewSettings> <syncfusion:TimelineViewSettings AppointmentTemplate="{StaticResource appointmentTemplate}"/> </syncfusion:SfScheduler.TimelineViewSettings> <syncfusion:SfScheduler.AppointmentMapping> <syncfusion:AppointmentMapping StartTime="From" EndTime="To" Subject="EventName" AppointmentBackground="Background" IsAllDay="IsAllDay"/> </syncfusion:SfScheduler.AppointmentMapping> </syncfusion:SfScheduler>
C#
By using the PreviousMouseDown event of the Image, you can remove appointment from the ItemsSource.
public class ScheduleBehavior : TargetedTriggerAction<Image> { Image image; protected override void Invoke(object parameter) { image = this.AssociatedObject as Image; image.PreviewMouseDown += Button_PreviewMouseDown; } private void Button_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { var schedule = (this.TargetObject as SfScheduler).DataContext as SchedulerViewModel; var d = (e.OriginalSource as FrameworkElement).DataContext as Events; var itemSource = schedule.Appointments; if (itemSource != null && itemSource.Contains(d)) { itemSource.Remove(d); } } protected override void OnDetaching() { base.OnDetaching(); image.PreviewMouseDown -= Button_PreviewMouseDown; image = null; } }
Conclusion
I hope you enjoyed learning about how to add delete icon to each appointment of the WPF Scheduler (Calendar)
You can refer to our WPF Schedule Feature Tour page to know about its other groundbreaking feature representations. You can also explore ourdocumentation to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trialto check out our other controls.
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!