How to Assign Context Menu to Appointment View
Using the custom Style for an Appointment view you can assign the context menu to appointments. Here is what to do:
1. Create Context Menu as part of your application or window resources. For example:
<ContextMenu x:Key=”AppContextMenu”>
<MenuItem Header=”Item 1″ />
<MenuItem Header=”Item 2″ />
<MenuItem Header=”Item 3″ />
</ContextMenu>
2. Create custom style for AppointmentView like such:
<Style TargetType=”{x:Type s:AppointmentView}” x:Key=”{ComponentResourceKey TypeInTargetAssembly=local:Window1, ResourceId=AppView}”>
<Setter Property=”ContextMenu” Value=”{StaticResource AppContextMenu}” />
</Style>
3. Assign custom style to your appointment, for example:
Appointment appointment = new Appointment();
appointment.Subject = “Appointment with Context Menu”;
appointment.StartTime = DateTime.Today.AddHours(9);
appointment.EndTime = appointment.StartTime.AddHours(1);
appointment.StyleResourceName = new ComponentResourceKey(typeof(Window1), “AppView”);
// Add appointment to the model
_Model.Appointments.Add(appointment);
From your context menu handlers, like Command.Executed event, you can use CalendarView.SelectedAppointments collection to get which appointments were right-clicked.
Related posts:
Leave a Reply!