How Can I Assign a Resource to an Appointment Programmatically

4 posts, 0 answers
  1. Anthony
    Anthony avatar
    2 posts
    Member since:
    Aug 2013

    Posted 22 Aug 2013 Link to this post

    Hi there,

    I'm trying to assign resources to appointments in the code behind. When I assign them, the appointment displays the correct resource when I edit the appointment, however the appointment itself is displayed in the blank resource column.

    Here is the XAML:
    <telerik:RadScheduleView x:Name="ScheduleView" SnapAppointments="True">
        <telerik:RadScheduleView.ResourceTypesSource>
            <telerik:ResourceTypeCollection>
                <telerik:ResourceType DisplayName="Room" Name="Room">
                    <telerik:Resource DisplayName="Room 1" ResourceName="Room 1" ResourceType="Room"/>
                    <telerik:Resource DisplayName="Room 2" ResourceName="Room 2" ResourceType="Room"/>
                </telerik:ResourceType>
            </telerik:ResourceTypeCollection>               
        </telerik:RadScheduleView.ResourceTypesSource>
        <telerik:RadScheduleView.GroupDescriptionsSource>
            <telerik:GroupDescriptionCollection>
                <telerik:ResourceGroupDescription ResourceType="Room" ShowNullGroup="True"/>
            </telerik:GroupDescriptionCollection>
        </telerik:RadScheduleView.GroupDescriptionsSource>
        <telerik:RadScheduleView.ViewDefinitions>
            <telerik:DayViewDefinition DayStartTime="7:00" DayEndTime="19:00" MajorTickLength="1h" MinorTickLength="10min"/>
            <telerik:WeekViewDefinition DayStartTime="7:00" DayEndTime="19:00"/>
        </telerik:RadScheduleView.ViewDefinitions>
    </telerik:RadScheduleView>

    And here is the code behind:
    private ObservableCollection<Appointment> appointments;
    void ExamRoomScheduler_Loaded(object sender, RoutedEventArgs e)
    {           
        appointments = new ObservableCollection<Appointment>();
        ScheduleView.AppointmentsSource = appointments;
     
        ExamRoomAppointment temp;
     
        temp = new ExamRoomAppointment("Test", DateTime.Now, DateTime.Now.AddMinutes(20), "Room 1");
        appointments.Add(temp);           
        temp.Resources.Add(new Resource() { ResourceType = "Room", ResourceName = "Room 1", DisplayName = "Room 1" });
    }

    ExamRoomAppointment inherits from Appointment.

    I must be doing something wrong here but I can't seem to figure it out!

    Thanks,
    Anthony
  2. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 26 Aug 2013 Link to this post

    Hi Anthony,

    If you need to add resources at run-time I would suggest that you check the following help article from our documentation:
    http://www.telerik.com/help/wpf/radscheduleview-howto-update-resources.html#Adding_Resources

    I'm also attaching here a sample project which demonstrates how to completely set up the resources in the code behind, please check the attachment.

    Hope this helps. If you have any other questions let us know.

    Regards,
    Kalin
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Anthony
    Anthony avatar
    2 posts
    Member since:
    Aug 2013

    Posted 26 Aug 2013 Link to this post

    Thanks Kalin,

    Unfortunately that's not what I'm looking for. Adding the resources at run time isn't a problem. The issue is that I need to add the resources to the appointments so that they are grouped properly. When I assign the resources to the appointment the appointment editor shows the resource but the appointment is displayed in the blank group.

    Anthony
  5. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 27 Aug 2013 Link to this post

    Hi Anthony,

    In order to have the appointment assigned to a particular resource you should add the same instance of the resource which is added to the ScheduleView resources. Please checked attached the same sample project which is modified to show the exact approach.

    Hope this will work for you.

    Regards,
    Kalin
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top