This question is locked. New answers and comments are not allowed.
Hello,
I've created a custom AppointmentDialogViewModel - "CalendarDialogViewModel" - and I'm trying to bind to it from the control template of the RadScheduleView's Edit Appointment Dialog.
In the constructor for my view - "ucCalendarView" - I'm instantiating the dialog's view-model as a private field in the view's code-behind:
Aaron
I've created a custom AppointmentDialogViewModel - "CalendarDialogViewModel" - and I'm trying to bind to it from the control template of the RadScheduleView's Edit Appointment Dialog.
In the constructor for my view - "ucCalendarView" - I'm instantiating the dialog's view-model as a private field in the view's code-behind:
public ucCalendarView(ViewModels.CalendarViewModel.CalendarState state){ this.DataContext = new ViewModels.CalendarViewModel(state); this._calendarDialogViewModel = new CalendarDialogViewModel(); this._calendarDialogViewModel.State = state; InitializeComponent();}
This is how I'm setting "_calendarDialogViewModel" as the dialog's DataContext:
/// <summary>/// The custom AppointmentDialogViewModel--CalendarDialogViewModel--is set here./// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void controlTemplateRootGrid_Loaded(object sender, RoutedEventArgs e){ // Save the dialog view-model: this._calendarDialogViewModel.DialogViewModel = (AppointmentDialogViewModel)((FrameworkElement)sender).DataContext; // Initialize start and end times: this._calendarDialogViewModel.DialogViewModel.ActualStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.AddHours(1).Hour, 0, 0); this._calendarDialogViewModel.DialogViewModel.ActualEnd = this._calendarDialogViewModel.DialogViewModel.ActualStart.AddHours(1); // Substitute the CalendarDialogViewModel for the default one: ((FrameworkElement)sender).DataContext = this._calendarDialogViewModel;}
"controlTemplateRootGrid" is the Grid immediately inside the "EditAppointmentTemplate" ControlTemplate. I have a RadComboBox inside this Grid and its SelectedItem property is bound like this:
<telerik:RadComboBox x:Name="rcmbClassResourceSelection" Grid.Row="0" Grid.Column="4" Width="100" Margin="3" SelectedItem="{Binding DialogViewModel.Occurrence.Appointment.SqlAppointmentClass, Mode=TwoWay}" IsEditable="False" telerik:StyleManager.Theme="{StaticResource Theme}"> <telerik:RadComboBox.Items> <telerik:RadComboBoxItem Content="Appointment"/> <telerik:RadComboBoxItem Content="Due"/> <telerik:RadComboBoxItem Content="Tickler"/> </telerik:RadComboBox.Items></telerik:RadComboBox>
Now when I create a new appointment, the following method in my CalendarDialogViewModel executes.
public void OnAppointmentCreating(object sender, AppointmentCreatingEventArgs e){ // Set the SqlAppointmentClass of the appointment being created: (e.Appointment as SqlAppointment).SqlAppointmentClass = this.SqlAppointmentClass; }
But when the Edit
Appointment Dialog appears, the RadComboBox has no selected item. I've tried a number of different things with
no success as yet. I'm trying to figure out how I should set the Edit Appointment dialog's DataContext to my custom view-model and how to do the data binding.
Aaron