WPF Ribbon control and commands to bind to the ribbon buttons inside each tab.

Topics: Prism v4 - WPF 4
Jan 16, 2014 at 4:34 PM
Edited Jan 16, 2014 at 4:38 PM
In a Ribbon control, I have the following Tabs:
Home
     Main
     Recent 
     New Student
     New Course
Students
     Save
     New
     Delete
     Search
     Print
Courses
    Save
    New
    Delete
    Print
Help
For Home when you click Recent, Home, New Student or New Course, I am using regionmanger to navigate to the form.

When I am in Students tab of the ribbon, Search can do the same to navigate using region manager to take me to a Search Form. Easy work :)

When I am in a New Student Form, the Save, and Delete button must use the commands of the New student form viewmodel.

For print, I will have to use the regioncontext information from New Form to pass to print preview based on what they wanted to print from the student form.

My question is how do I bind the delegate command of the NewStudentViewModel that has SaveCommand, DeleteCommand to the Save and Delete Buttons in the RibbonControl?

The same requirement is there for the Courses Tab

My Shell is
TopRegion (Ribbon)
LeftRegion (Some search capability)
MainRegion (Main Content where New Student Form will be displayed)

With the above structure, My TopRegion (Call it AppMenu) does not have access to the NewStudentViewModel or NewCourseViewModel.

I am kinda stuck here on the approach. If this approach not correct, please advise any better ideas
Jan 16, 2014 at 5:51 PM
Hi isakavis,

If I understood correctly, you would have a TopRegion that shows each of the 3 tabs with their corresponding buttons as described in the structure like Save and Delete. Then, each Student or Course form would be displayed in the MainRegion.
Prism provides a simple way for communication between Regions by using the Event Aggregator. You may find how it works in the following Prism Guide chapter:

What you would need to do, is to bind the command buttons on their corresponding datacontext ViewModel just like any other command. So now, you would get the Save or Delete delegate commands publish and raise an Event on the EventAggregator, which it would be handled by the NewStudentViewModel or NewCourseViewModel event handler. In order to get the event handled, you would need the NewStudentViewModel and NewCourseViewModel subscribe to the corresponding Event that they would handle.

Notice that you may need different events for the Save and Delete command as each one would be handled in a different way.

I hope this helped you,
Regards.

Gabriel Ostrowsky
https://blogs.southworks.net/gostrowsky
Marked as answer by isakavis on 1/17/2014 at 4:50 AM