Showing posts with label Messenger. Show all posts
Showing posts with label Messenger. Show all posts

Tuesday, 16 August 2011

Silverlight Application Framework

This custom framework contains the following functionality:

Client

  • Ribbon menu bar (from DivElements)
  • Navigation frames for the main container and content pages
  • MVVM architecture
  • MVVM Light Locator to make ViewModels available to Views
  • MVVM Light Messenger for content navigation, status updates and logout
  • MVVM Light RelayEvent for Commanding in View Models
  • MVVM Light EventToCommand for key press binding in ViewModels
  • Custom client-side session data management
  • Mockable dialog box service
  • Custom Silverlight “loader”

Server

  • WCF Services (not WCF RIA Services)
  • Custom ASP.NET Authentication and login UI
  • ASP.NET Authorisation to allow for both secure and unsecure services
  • Text to Path web service to generate Xaml Path data from any string & font

 

Silverlight Application Framework demo from Steven Hollidge on Vimeo.

Navigation with the Ribbon and MVVM Light Messenger

The Ribbon button has a tag property that has the desired Uri set as its content.

When the button is clicked, a message is sent that contains the desired Uri.

The messenger listener receives the message and calls the ContentFrame.NavigateTo method.

Click here to download the source code:

http://stevenhollidge.com/blog-source-code/SilverlightExampleApp.zip

PS    Prefer a Treeview Menu to the Ribbon?

If you prefer the style of a Tree View menu, which is free compared to the Ribbon which is licensed, you can check out my blog posting here.

http://stevenhollidge.blogspot.com/2011/06/treeview-menu-for-silverlight.html

[ScreenShot008%255B5%255D.png]

Wednesday, 18 May 2011

MVVMLight Messenger for Loosely Coupled Events

The Messenger class within MVVMLight gives developers the ability to publish an application wide event using messages that allow a subscriber to react without either the publisher or subscriber knowing anything about each other.

As always with MVVMLight it’s really simple to do.

In this example, I wanted a user to be able to click on the main menu of my application, shown on the left hand side of the screenshot below, which would update the content pane on the right hand side.

image

The main menu is a user control whilst the content pane is a navigation frame located within the MainPage.xaml.

To allow two pieces of code to communicate with each other, without knowing anything about each other, I will use the Messenger class in 3 simple steps.

1 Create a strongly typed message

 

2 Register a subscriber to the message type

Register the MainPage as the subscriber so that when the message is received the Uri within the message will be passed to the NavigateTo method to update the content pane.

 

3 Lastly, publish the message

 

When the TreeView menu is clicked the code behind checks for a Uri within the selected TreeViewItem then creates a message containing the Uri and publishes it to your application.

Summary

Using messages within your application can be a great way for your components to communicate whilst maintaining a loosely coupled architecture. This is important because you don’t have any nasty hard coded dependencies. Hard coded dependencies result in brittle, inflexible systems that can be hard to extend in the future.

The Messenger class in MVVMLight provides similar functionality to the EventAggregator class in PRISM.

You can download the WCF RIA sample application here:

http://www.stevenhollidge.com/blog-source-code/Silverblade5-WCF-RIA-MVVMLight-Messenger.zip

Please note that for demo purposes only menu options “Home > Search” and “Client > Details” have views that can be displayed within the content pane.  All other menu options will return an error.