Binding to Telerik RadScheduleView

Topics: Conventions
Jun 14, 2011 at 5:04 PM

I'm new to Caliburn.Micro and I'm trying to bind to the Telerik RadScheduleView.

I have a ViewModel with Appointments property:

public IEnumerable<IAppointment> Appointments {
	get {
		return appointments;
	}
	set {
		appointments = value;
		NotifyOfPropertyChange(() => Appointments);
	}
}

And I've added a convention:

ConventionManager.AddElementConvention<RadScheduleView>(RadScheduleView.AppointmentsSourceProperty, "AppointmentsSource", "ValueChanged");

I can see the RadScheduleView, but the appointments don't seem to bind.

Is this the correct approach?

Coordinator
Jun 14, 2011 at 5:42 PM

Can you show me the Xaml? Not just for the Rad control but some of the surrounding xaml as well? Thanks.

Jun 15, 2011 at 10:03 AM

View:

<Grid>
	<Grid.RowDefinitions>
		<RowDefinition Height="*" />
	</Grid.RowDefinitions>
	<t:RadScheduleView Grid.Row="0"
                        AppointmentsSource="{Binding Appointments}">
		<t:RadScheduleView.ViewDefinitions>
			<t:MonthViewDefinition/>
            <t:WeekViewDefinition/>
            <t:DayViewDefinition/>
            <t:TimelineViewDefinition/>
		</t:RadScheduleView.ViewDefinitions>
	</t:RadScheduleView>
</Grid>

ViewModel:
public class EventsWorkspaceViewModel : Screen, IWorkspace {
	protected override void OnActivate() {
		Appointments = new[] {
				new Appointment {
					Start = DateTime.Now,
					Subject = "Appointment"
				}
			};
		base.OnActivate();
	}

	IEnumerable<IAppointment> appointments;
	public IEnumerable<IAppointment> Appointments {
		get {
			return appointments;
		}
		set {
			appointments = value;
			NotifyOfPropertyChange(() => Appointments);
		}
	}
}



 

Jun 15, 2011 at 11:46 AM

I tried replacing the RadScheduleView with a ListBox and that works, so I know everything is setup ok. It must be to do with how the conventions are being applied to the RadScheduleView. How do I go about debugging issues like this? I put a debugger in (using ILog), but this didn't give me any useful information.

I'm going to try adding the Caliburn project to my application so I can step through the source and try to figure it out. Is that a good way to solve these issues?

btw, love the framework!

Cheers,

Jon

Coordinator
Jun 15, 2011 at 1:20 PM

Hmm. Everything looks right. You could include the source and step through the view model binder code to see what is happening. You could also plug a logger into the LogManager and see what the system reports.

Jun 15, 2011 at 2:03 PM

You say that the appointments don't seem to bind, yet in the source code you posted you are directly binding your Appointments property to the RadScheduleView, so the binding is nothing to do with Caliburn.Micro. Is that a typo in the source you posted or actually what you have?

If that binding is present, and you say it works with a ListBox, then that suggests that there is something wrong with your RadScheduleView setup or the items you are binding to it (I know nothing about how that particular control works).

Jun 15, 2011 at 5:09 PM

OK, yes I was directly binding. The issues remains the same though. I've now changed to:

<t:RadScheduleView x:Name="Appointments" Grid.Row="1">
    <t:RadScheduleView.ViewDefinitions>
        <t:MonthViewDefinition/>
        <t:WeekViewDefinition/>
        <t:DayViewDefinition/>
        <t:TimelineViewDefinition/>
    </t:RadScheduleView.ViewDefinitions>
</t:RadScheduleView>

The AppointmentSource is being set, but there are no items in it. If I remove x:Name="Appointments", the RadScheduleView complains that it needs and Appointment source, so the binding must be working.

If I put a code behind file in and directly set the source, the items appear (Appointments.AppointmentSource = MyAppointments). I'm really confused, is this a problem with my Caliburn setup or the RadScheduleView control? I've tried working through the code, but it's pretty complicated and you need a deep understanding of databinding and dependency properties.

Jun 15, 2011 at 5:18 PM

What about when you had the binding specified directly, as in the Xaml source in your second post -  did that work the same as when you set the appointments from the codebehind?

Jun 15, 2011 at 8:00 PM

No, that didn't work the same. The appointments didn't show.

Jun 16, 2011 at 9:31 AM

Turned out to be a problem with my control setup. I needed to bind to a collection of Appointments, not IAppointment. Thanks for the help though, I understand a lot more about the framework now.