Quantcast
Viewing all articles
Browse latest Browse all 7205

Implementing MVVM

This example illustrates how to implement an MVVM pattern (see Model View ViewModel) in a scheduling application. Model is represented by the Car and CarScheduling class generated via an Entity Framework layer. The SchedulerViewModel class represents a view model. It exposes model collections (for appointments and resources) to the view that is not defined separately integrated into the MainWindow.xaml markup to keep things simple. In addition, we define two commands in the view model: AppointmentsModifiedCommand and FetchAppointmentsCommand. We cannot use the EventToCommand from the MVVM Light Toolkit to transform the corresponding SchedulerStorage events to these commands because these events are not routed (they are defined as regular CLR events). Thus, we have created a special SchedulerHelper class with the corresponding attached properties to be able to map events to commands in XAML in the following manner:

[XAML]
<dxsch:SchedulerControlName="schedulerControl1"ActiveViewType="Timeline"GroupType="Resource"local:SchedulerHelper.AppointmentsModifiedCommand="{Binding AppointmentsModifiedCommand}"local:SchedulerHelper.FetchAppointmentsCommand="{Binding FetchAppointmentsCommand}"> ...

Note: This approach is illustrated in the Use EventToCommand with Appointment events ticket. Alternatively, you can implement the approach from the Scheduler - Event handling - EventTrigger / EventToCommand / MVVM ticket, i.e., use a custom-made CLREventTrigger class.

We handle the SchedulerStorage.FetchAppointments Event in the manner described in the How to handle FetchAppointments event when the Scheduler is bound to the Entity Framework datasource example.

Question Comments

Added By: Marcin Sulecki at: 4/29/2015 11:47:12 PM    

IMHO, simpler solution is use to EventToCommand class:

 <dxsch:SchedulerControl.Storage>
                      <dxsch:SchedulerStorage>
                          <dxmvvm:Interaction.Behaviors>
                              <dxmvvm:EventToCommand EventName="AppointmentsInserted" Command="{Binding AppointmentsAddedCommand}" />
                              <dxmvvm:EventToCommand EventName="AppointmentsChanged" Command="{Binding AppointmentsModifiedCommand}" />
                              <dxmvvm:EventToCommand EventName="AppointmentsDeleted" Command="{Binding AppointmentsDeletedCommand}" />

                          </dxmvvm:Interaction.Behaviors>

 </dxsch:SchedulerControl.Storage>

Added By: Oleg (DevExpress Support) at: 4/30/2015 3:35:16 AM    

You are absolutely correct, Marcin!
An alternative approach to bind the SchedulerControl's event with a specific command of the View Model is to use the dxmvvm:EventToCommand class.
Thank you for posting your solution here.


Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>