This is a migrated thread and some comments may be shown as answers.

Multiple appointment types

2 Answers 124 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Claire
Top achievements
Rank 1
Claire asked on 29 Oct 2015, 09:00 PM

I need to have more than one appointment type, let's them be AppX and AppY, both derived from your Appointment class. One may have properties that the other does not, but at a minimum both have a subject, a start time and end time.

The AppointmentsSource property being bound to a Collection of Appointment objects, I can thus add AppX and AppY objects to it. 

So far, so good. Each appointment type is displayed in the schedule the way I want (I use a different template for each type).

Now I want to be able to show a create/edit dialog that is customized to each type of appointment. DialogX and DialogY would be associated to AppX and AppY, respectively. And if the user double-clicks on an empty slot, I want to create an appointment of type AppX through DialogX.

This is where I'm stuck.

I thought of hooking to the AppointmentCreating and AppointmentEditing events, and show the appropriate dialog there. Is this the correct technique?

Or would you not happen by any chance to have a sample that illustrates how this could be done?

 

2 Answers, 1 is accepted

Sort by
0
Claire
Top achievements
Rank 1
answered on 30 Oct 2015, 01:49 PM

A better solution than hooking to the events mentioned would be to make use of a template selector to select the appropriate dialog template based on the appointment type.

Here's a summary:

1. Set up the RadScheduleView's EditAppointmentDialogStyle property
tlk:RadScheduleView  EditAppointmentDialogStyle="{StaticResource myEditAppointmentDialogStyle}" ...

2. Set up the Style's Template property
<Style x:Key="myEditAppointmentDialogStyle" TargetType="tlk:SchedulerDialog">
<Setter Property="Template" Value="{StaticResource myEditAppointmentTemplate}" />
...
</Style>

3. ControlTemplate looks like this:
<ControlTemplate x:Key="myEditAppointmentTemplate" TargetType="tlk:SchedulerDialog">
<DockPanel  x:Name="DialogRoot" >
<ContentControl  
Content="{Binding DataContext.Occurrence.Appointment, ElementName=DialogRoot}" 
ContentTemplateSelector="{StaticResource myDialogTemplateSelector}">
</ContentControl >
</DockPanel>
</ControlTemplate>

4. Definition of actual template selector
<views:DialogTemplateSelector 
   TypeXTemplate="{StaticResource myTypeXTemplate}" 
   TypeYTemplate="{StaticResource myTypeYTemplate}" 
   x:Key="myDialogTemplateSelector" />

5.  The data templates for each appointment type:
<DataTemplate x:Key="myTypeXTemplate">
<DockPanel>
<DockPanel.Resources>
<viewmodels:EditTypeXDialogViewModel
Appointment="{Binding}"
x:Key="CustomDialogXViewModel" />
</DockPanel.Resources>
...
</DockPanel>
</DataTemplate>

<DataTemplate x:Key="myTypeYTemplate">
<DockPanel>
<DockPanel.Resources>
<viewmodels:EditTypeYDialogViewModel
Appointment="{Binding}"
x:Key="CustomDialogYViewModel" />
</DockPanel.Resources>
...
</DockPanel>
</DataTemplate>

6. In the DialogTemplateSelector class (derived from DataTemplateSelector), method SelectTemplate returns the template type based on the type of the item argument: if type is AppY, return TypeYTemplate, else return TypeXTemplate. 

 

Ohad
Top achievements
Rank 3
Bronze
Iron
Iron
commented on 12 Feb 2023, 02:01 PM | edited

Thanks for the nice way you suggested doing it,

Can you explain the DockPanel Resources? What did you put there?

I used your suggested way and when I open the Appointment I don't have StartTime EndTime etc.

That is, the appointment dialog DataContext is of my custom type

And I want the DataContext to remain AppointmentDialogViewModel

I would appreciate it if you could explain what the problem could be as a result of the fact that I was missing the part of the

DockPanel Resources

0
Accepted
Nasko
Telerik team
answered on 02 Nov 2015, 11:31 AM
Hi Claire,

Thank you for sharing with the community your approach. Indeed the chosen by you solution of using a Template selector is the most appropriate one. Basically you could create as many EditAppointmentDialogStyles as you need and apply them for the the different types of Appointments.

The other approach of using AppointmentCreating and AppointmentEditing events seems to be also an appropriate one, so based on your scenario you could choose which one best suits it and use it.

If you have any additional questions or concerns regarding Telerik controls, please do not hesitate to contact us.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ScheduleView
Asked by
Claire
Top achievements
Rank 1
Answers by
Claire
Top achievements
Rank 1
Nasko
Telerik team
Share this question
or