Silverlight / CompositeWPF / Prism regions

Suggested reading: Martin Fowler on the PresentationModel 

Source Code available  http://www.CodePlex.com/SDMS  

CompositeWPF/Prism regions permit you to easily design a system that clearly has a Separation of Concerns.  In the figure below you see the XAML code that defines the regions for the Main Employee Manager screen:

This is particularly useful for tabs because you don't have to kludge up your TabControl with alot of controls - above you see all the XAML code required for the Information, In Work and Assigned tabs.

Below you'll see where the Module's Initialize method will register the types, resolve each presenter (instantiate it) and then apply the presenter's view to the applicable regions:


Click HERE for Video Clip Demo (Windows 7 users may have to right click then Save Target As)


The code for the Status Bar's Presenter, View and Interface is below.  Note: all of the Employee Module views share a single presentation model.  

Below is the source code for the EmployeeModule\Views\frmStatus\frmStatusPresenter.cs

using EmployeeModule.PresentationModels;

using Microsoft.Practices.Unity;

using Microsoft.Practices.Composite.Events;

using EmployeeModule.Events;

using System.Windows.Controls;

using System;

 

namespace EmployeeModule.Views.frmStatus

{

    public class frmStatusPresenter

    {

        [Dependency]

        public IEventAggregator aggregator { get; set; }

 

        /// <summary>

        /// View reference

        /// </summary>

        public IfrmStatusView View { get; set; }

 

        /// <summary>

        /// Constructor : setup class

        /// </summary>

        /// <param name="container"></param>

        /// <param name="view"></param>

        public frmStatusPresenter(IUnityContainer container,

            IfrmStatusView view, IEventAggregator aggregator)

        {

            this.View = view;

            this.aggregator = aggregator;

 

            // Provide the presentation model to the view so that

            // it can set it's DataContext to it

            view.Model =
                 container.Resolve<EmployeePresentationModel>();

 

            // Subscribe to the StatusBar event

            aggregator.GetEvent<StatusBarEvent>()

                 .Subscribe(StatusBarEventHandler, true);

 

        }

 

        public void StatusBarEventHandler(StatusBarData panel)

        {

            switch (panel.Panel)

            {

                case StatusPanel.Left:

                    View.FindControl<TextBlock>("stsLeft").Text =
                             panel.Message;

                    View.FindControl<TextBlock>("stsRight").Text =
                             string.Format("ID:{2} -- {0} {1}",

                        View.Model.SelectedEmployee.FirstName,

                        View.Model.SelectedEmployee.LastName,

                        View.Model.SelectedEmployee.EmployeeID);

                    break;

 

                case StatusPanel.Right:

                    View.FindControl<TextBlock>("stsRight").Text =
                            panel.Message;

                    break;

 

            }

        }

    }

}

 


Tags: , ,
Categories: CompositeWPF | Silverlight


Actions: E-mail | Permalink |  Grammar/Typo/Better way? Please let me know