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

modify Binding in code behind

4 Answers 612 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Bart
Top achievements
Rank 1
Bart asked on 16 Sep 2016, 02:25 PM

Hi Guys,

I'm struggling with this issue for a couple of day's now and I assume this is because I'm new to WPF. but I need some help with the following.

I am creating a custom planner, and for this I'm using the radschedular like this

<telerik:RadScheduleView x:Name="MachineplanningScheduleView"
                         ActiveViewDefinitionIndex="{Binding ActiveViewDefinitionIndex, Mode=TwoWay}"                              
                         CurrentDate="{Binding SelectedDate, Mode=TwoWay}"
                         SelectedAppointment="{Binding SelectedAppointment, Mode=TwoWay}"
                         ShowDialog="ShowDialog"
                         AppointmentsSource="{Binding Appointments}"
                         NavigationHeaderVisibility="Collapsed"
                         GroupDescriptionsSource="{Binding GroupDescriptions}"
                         GroupHeaderContentTemplateSelector="{StaticResource GroupHeaderContentTemplateSelector}"
                         ResourceTypesSource="{Binding ResourceTypes}">

The Binding Appointments works perfect and the calender gets updated when appointments get changed.

The ShowDialog function in the codebehind should do some database updates and then update the planning without showing the dialog.
The database updates are going fine, I can cancel the dialog and also I'm able to update the ResourceTypesSource like this

    db.SaveChanges();
 
    RadScheduleView rsv = (RadScheduleView)sender;
    rsv.AppointmentsSource = MachineplanningViewModel.GetCalendarAppointments();
 
    e.Cancel = true;
}
the only problem is, while calling "rsv.AppointmentsSource" I lose my binding on Appointments and the calender doesn't get updated anymore when I switch user.

so my question is, how can I update "Appointments" directly from codebehind so I won't lose my binding.

 

I hope my explanation is clear and someone can help me.

 

Thank you.

4 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 19 Sep 2016, 07:29 AM
Hi Bart,

I need to ask you for some additional details on the required approach, so we could try to find a suitable solution. First, why you'd need to set again the AppointmentsSource in ShowDialog event? Can you give us more information on the exact use case you're covering?

Also, have in mind, that you could use AppointmentCreated, AppointmentEdited and AppointmentDeleted events of RadScheduleView and update the database in their event handlers.

Looking forward to your reply.

Regards,
Yana
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Bart
Top achievements
Rank 1
answered on 19 Sep 2016, 11:57 AM

Hi Yana,

Thank you for the response.
I the specific situation people are only able to plan a specific appointment for the whole day, so there is no need for a dialog box.
Single or double clicking with the mouse should add the appointment. According to the algorithm appointments of other persons in the overview can change when I add an appointment. Also the algorithm can decide that my appointment will be 2 days or longer instead of one. This all will be updated in the database and then the appointments are read from the database again.

If I don't update AppointmentsSource  in the showDialog event added appointments won't appear until I reload the schedular again.
I'm aware of those events but they are all handled in the code behind, non of them I can bind to another function.

I hope what I write here makes any sense.

With Kind Regards

 

Bart

0
Bart
Top achievements
Rank 1
answered on 20 Sep 2016, 07:37 AM

Hi,

I really hate to tell this but I have found a solution for my issue

AppointmentsSource="{Binding Appointments, Mode=TwoWay}"

the thing is, I really needed to use "Mode=TwoWay" here.

I'm a little bit embarrassed that it took me that long to figure this out.

 

thanks for your help.

0
Accepted
Yana
Telerik team
answered on 20 Sep 2016, 07:43 AM
Hello Bart,

Thank you for sending the additional information.

In this case, you could either use the ScheduleView methods for creating/editing appointments which will update the UI as explained in the following topics:
Create Appointment Using Code
Edit Appointment Using Code

Or you could set the AppointmentsSource binding with code, please check the following snippet:

RadScheduleView rsv = (RadScheduleView)sender;
 
Binding myBinding = new Binding();
myBinding.Source = this.DataContext asMachineplanningViewModel;
myBinding.Path = new PropertyPath("Appointments");
myBinding.Mode = BindingMode.TwoWay;
 
BindingOperations.SetBinding(rsv, RadScheduleView.AppointmentsSourceProperty, myBinding);

I hope this would be helpful.

Regards,
Yana
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
Calendar
Asked by
Bart
Top achievements
Rank 1
Answers by
Yana
Telerik team
Bart
Top achievements
Rank 1
Share this question
or