Hi,
I am trying to show the number of appointments for any given day on the month view using the MonthItemTemplate. The schedule contains multiple resources.
The suggestion at https://www.telerik.com/forums/number-of-appointments-per-day does not work because the TimeRulerItemProxy I can pass to a MultiBindingConverter does not have any idea of the resource it belongs to.
Is there a way to get the resource so that I can tally the appointments for the resource on any given day?
Regards
Anthony
4 Answers, 1 is accepted
I'm attaching a sample project based on the forum thread you've referenced which seems to provide the desired result. For the purpose, I've used the AppointmentsSource property of the RadScheduleView control and checked how many appointments have the same date as the current TimeRulerItemProxy's one.
Please have a look and let me know if such an approach would work for you.
Regards,
Dilyan Traykov
Progress Telerik
Hi,
This approach does not work because it is not considering the different resources. I need to show a separate tally per day per resource.
Thanks
Anthony
To also take the resources of the appointment into account, you will need to pass the DataContext of the TimeRulerItem to get ahold of its resources. This can be done in the following manner:
<
MultiBinding
Converter
=
"{StaticResource TimeRulerToAppointmentCountConverter}"
>
<
Binding
Path
=
"DateTime"
/>
<
Binding
Path
=
"AppointmentsSource"
RelativeSource
=
"{RelativeSource Mode=FindAncestor, AncestorType={x:Type telerik:RadScheduleView}}"
/>
<
Binding
Path
=
"DataContext"
RelativeSource
=
"{RelativeSource Mode=FindAncestor, AncestorType={x:Type telerik:TimeRulerItem}}"
/>
</
MultiBinding
>
public
object
Convert(
object
[] values, Type targetType,
object
parameter, CultureInfo culture)
{
if
(values.Length != 3)
throw
new
TargetParameterCountException(
"TimeRulerToAppointmentCountConverter expects two parameters."
);
if
(!(values[0]
is
DateTime) || !(values[1]
is
IList<Appointment>) || !(values[2]
is
GroupHeader))
return
String.Empty;
var date = (DateTime) values[0];
var items = values[1]
as
IList<Appointment>;
var rulerGroup = values[2]
as
GroupHeader;
var resource = rulerGroup.ParentKeys.Last()
as
IResource;
// you may need to modify this logic if you have multiple resource types
var resourceName = resource.ResourceName;
var count = items.Where(a => a.Start.Date == date && a.Resources.Any(r => r.ResourceName == resourceName)).Count();
return
count.ToString();
}
Please let me know if this works for you.
Regards,
Dilyan Traykov
Progress Telerik
Hi Dilyan,
That works great. I just needed to change the IList to an IEnumerable as my AppointmentSource was an ObservableCollection.
Thanks for your help.
Regards
Anthony