Posted By: Mike Taulty | Oct 27th @ 3:31 AM | 4,627 Views | 13 Comments

This is part 10 of a series of screencasts illustrating some of the ideas found in "Prism" or the "Composite Application Guidance" from the Patterns and Practices team that can be used to build Silverlight applications in a way that lends itself to testability and modularity.

In talking to customers building business applications with Silverlight I find that Prism (and it's friend Unity) is frequently mentioned but not everyone has seen it and so I thought I would explore it myself and capture some of the results of that exploration here.

We start off with some fairly basic code which we move towards making use of dependency injection and modularity;

and then we move that code into the Silverlight world and try to illustrate some specific areas of Prism;

and then finally we try and bring some of these concepts together in a longer, more realistic example of a simple Email application built using the Prism framework - warning, this is a much longer session but I wanted something that draws things together;

The recommendation would be that you watch the 10 screencasts in order but if that feels like too long a process or if you're already very familiar with concepts like dependency injection and containers like Unity then perhaps watch the last screencast first and then refer back to the previous screencasts if certain areas need more illumination.

I put the source code for Video 10 here for download as it's a bigger set of source and something you might want to explore after the video - this does not necessarily represent "best practise" but is, instead, just meant to illustrate some of the Prism ideas.

Rating:
1
0
IanBlackburn
IanBlackburn
mmmm coffee...

Hi Mike,

 

At around 30 minues you go and create your own commands for ListBoxSelectionChanged and TreeViewSelectionChanged - what are your opinions on using, for example, a TwoWay Binding to the ListBox SelectedItem property to the view model instead and then publish the event in the Setter?  Not such a nice solution perhaps but possibly easier in many of these cases.  Here's what I did for the MailListViewModel which seems to work fine:

 

Adding a binding as follows:

<ListBox SelectedItem="{Binding SelectedItem, Mode=TwoWay}"

 ScrollViewer.HorizontalScrollBarVisibility="Hidden" 

ItemsSource="{Binding Emails}">

 

Then had the following property on the view model:

 


private object _selectedItem=null; 

public object SelectedItem { 

   get { return _selectedItem; } 

   set { 

        _selectedItem = value; 

        EmailSelectionChangedEvent evt = eventAggregator.GetEvent<EmailSelectionChangedEvent>(); 

        MailViewModel viewModel = (MailViewModel)value; 

        evt.Publish(viewModel == null ? null : viewModel.Email); 

       } 

}

 

Can you see any problems with this approach?

IanBlackburn
IanBlackburn
mmmm coffee...

One other thought - you use converters in some of the views - I know that some MVVM guys think that you should never need a converter in the View since the ViewModel should prepare the data correctly for it.  I also know there are lots of discussions about MVVM currently and nothing really baked into the framework or tools to answer all the current questions - but just wondered what your opinion was.

 

Fantastic set of videos by the way - really detailed and incredibly useful - many thanks for the work you have put into them; I for one really appreciate the hands-on "live code" approach that you take...

 

Cheers

 

Ian

Nice screencasts, very well explained, a great start to learn how to use Prism and Unity.

Bravo!

 

Is it possible to have the code source from all samples, like you did for the last sample?

(In order to play with).

 

Thomas.

Microsoft Communities