How to get the dropped resource in WPF Scheduler (Calendar)
You can get the dropped resource of WPF SfScheduler by using the TargetResource property of the AppointmentDropping event in SfScheduler.
C#
Create a ViewModel class and add the appointment details.
public class SchedulerViewModel : NotificationObject
{
private ScheduleAppointmentCollection events;
private ObservableCollection<object> resources;
private List<string> eventNames;
public SchedulerViewModel()
{
CreateResources();
CreateResourceAppointments();
}
private void CreateResourceAppointments()
{
Events = new ScheduleAppointmentCollection();
Random randomTime = new Random();
List<Point> randomTimeCollection = this.GettingTimeRanges();
var resurceCollection = this.Resources as ObservableCollection<object>;
Events.Add(new ScheduleAppointment()
{
StartTime = dateTime1,
EndTime = dateTime1.AddHours(2),
Subject = this.eventNames[randomTime.Next(4)],
ResourceIdCollection = new ObservableCollection<object>() { scheduleResource.Id },
});
}
}
}
private void CreateResources()
{
Resources = new ObservableCollection<object>()
{
new SchedulerResource() { Name = "Sophia", Id = "1000" },
new SchedulerResource() { Name = "Zoey Addison", Id = "1001" },
new SchedulerResource() { Name = "James William", Id = "1002" },
};
}
}
XAML
Resources can be added to the scheduler by setting the ResourceGroupType property as Resource in SfScheduler. You can add the resource to the scheduler by using the ResourceCollection property.
<Window.DataContext>
<local:SchedulerViewModel/>
</Window.DataContext>
<Grid>
<syncfusion:SfScheduler x:Name="Schedule"
ViewType="Timeline"
ResourceGroupType="Resource"
ResourceCollection="{Binding Resources}"
ItemsSource="{Binding Events}" >
<interactivity:Interaction.Behaviors>
<local:SchedulerBehavior/>
</interactivity:Interaction.Behaviors>
</syncfusion:SfScheduler>
</Grid>
C#
You can get the dropped resource item by using the TargetResource property of AppointmentDropping event while drag and drop the appointment.
public class SchedulerBehavior : Behavior<SfScheduler>
{
SfScheduler scheduler;
protected override void OnAttached()
{
base.OnAttached();
scheduler = this.AssociatedObject;
this.AssociatedObject.AppointmentDropping += AssociatedObject_AppointmentDropping;
}
private void AssociatedObject_AppointmentDropping(object sender, AppointmentDroppingEventArgs e)
{
var dropitem = e.TargetResource.Name;
MessageBox.Show("Resource change into" + " " + dropitem, " ", MessageBoxButton.OK);
}
protected override void OnDetaching()
{
base.OnDetaching();
this.AssociatedObject.AppointmentDropping -= AssociatedObject_AppointmentDropping;
this.scheduler = null;
}
}
