Published: 10 Nov 2008
By: Oleg Zhukov

Oleg Zhukov talks about building applications with MVC#.

Contents [hide]


In the earlier articles (here and here - read them prior to proceeding) we got acquainted with MVC# - a framework for simplifying the usage of the Model-View-Presenter pattern in .NET applications. We have covered all basic requirements and scenarios of using the MVP architectural pattern. However in the real-world conditions application's requirements diverge from those basic ones. Complex applications often demand for an advanced customization and fine-tuning. And, of course, robust frameworks should cope well with such specific requirements.

This article steeps deeper into the MVC# framework capabilities demonstrating its advanced usage scenarios. These scenarios range from extending view and task descriptions to customizing navigation and presentation styles. Each advanced feature is covered in a separate article section and may be read independently.

Using 3rd-party components (Office 2007-like UI)

The major drawback of many existing MVC/MVP frameworks is that they require certain UI components to be used with them. For example the ASP.NET MVC framework comes with its own set of UI elements, CAB (Composite UI Application Block) is either not compatible with many 3rd-party components. With such frameworks a developer finds himself restricted in choosing the UI components he likes. MVC#, on the other hand, does not impose any limitations of such kind. Developers may use MVC# with any 3rd-party library they are committed to. In this article we are using MVC# with 3rd-party UI components for creating an Office 2007-like user interface.

The main form of our application will be constituted from a menu with toolbar strips, an Outlook-like navigation pane on the left and an Outlook-like content panel on the right (see the picture below). To apply the Outlook 2007 style to the menu and toolbar strips we will use an open-source 3rd-party renderer component by ComponentFactory (downloadable from here). The Outlook-like navigation pane we will use is the open-source component by Muhammed Sahin (get it here). And the Outlook-like content pane is the slightly modified Outlook-style panel from

Figure 1: The Outlook-like example application

The Outlook-like example application

By now we should have only placed the said 3rd-party controls on the form and set their basic properties. Later on we will handle events from these controls and make them interact with the framework.

Outlook-like navigation

When a user selects an item in the navigation pane an appropriate view should be shown in the content pane on the right. In MVC# the way of switching between views is defined by the views manager class. Therefore the desired kind of navigation can be implemented by writing a custom WinformsViewsManager subclass - OutlookLikeViewsManager.

Firstly, this new views manager should gain access to the content panel of the main form:

If a newly created view does not have a parent container then it should be placed inside the content panel:

Whenever a view is activated it should be placed on top over other views:

Finally, in the Main form code we should handle the selection of an item inside the navigation bar:

Extended view and interaction point definitions

The conventional way for describing View-Controller pairs is using [IPoint] attributes inside the task declaration. Since views in our application are divided into three categories (Mail, Notes, Tasks) we might want to supplement the [IPoint] attribute with additional category information. So we will introduce the [IPointEx] attribute and the InteractionPointInfoEx class:

For the new [IPointEx] attributes to be properly processed a custom TaskInfoByAttributesProvider descendant is required:

A similar technique is applied when extending view definitions. Say, we want to associate each view with the corresponding image name. Then we should introduce the [ViewEx] attribute and the ViewInfoEx class:

In order to interpret [ViewEx] attributes we also need to create a DefaultViewInfosProvider descendant:

Before starting the main task the framework should be configured to use the above TaskInfoByAttributesProviderEx and ViewInfosPrividerEx classes:

Finally, view navigation links inside the navigation pane should be added with properly set category and image:

Views in multiple assemblies

For projects with distinctly separated architecture, views may be spread among several DLL assemblies. If this is the case those assemblies should be appended to the MVCConfiguration.ViewsAssemblies collection:

Customized Controller creation

As a rule the controller type is specified in the interaction point description. However, instead of such explicit declaration the default controller type could be used. Each view category (Mail, Notes, Tasks) could be associated with its default controller type. Consider, for instance, the following declaration:

Since the controller type is left unspecified above then the default controller for the Notes category should be used - NotesController class.

Such functionality could be implemented by creating a custom Navigator subclass with overriden GetController method:

In the above code an interaction point with unspecified controller type gets associated to one of the default controller types (depending on the view category - see the switch construct above). And then the controller is created with this type.

To employ the new NavigatorEx class it should referenced with the help of the [Task] attribute:

Another option is applying the custom navigator class globally via the MVCConfiguration.NavigatorType property.

Adding views dynamically

In our example application a user should be able to add views dynamically by clicking the appropriate menu item. Depending on the clicked item views of different categories will be created:

The actual view creation method will reside in the OutlookLikeViewsManager class and will do the following: a) Add a new (properly configured) InteractionPointInfoEx instance to the interaction point descriptions collection for the task and b) Add a new (also configured) ViewInfoEx to the view descriptions collection for the task:


Throughout this article we have studied a number of advanced MVC# framework features. These features help dealing with complicated application's requirements which often appear in real-world projects. With the discussed customization techniques developers can fully harness MVC# power to creating complex Model-View-Presenter applications.

The source code of this example can be found under "Examples\Advanced (Office2007 UI and more)\" subfolder of the MVC# root folder. The framework itself can be downloaded from

<<  Previous Article Continue reading and see our next or previous articles Next Article >>

About Oleg Zhukov

Oleg Zhukov, born and living in Russia is Lead Engineer and Project Manager in a company which provides business software solutions. He has graduated from Moscow Institute of Physics and Technology (MIPT) (department of system programming) and has got a M.S. degree in applied physics and mathematics...

This author has published 5 articles on DotNetSlackers. View other articles or the complete profile here.

Other articles in this category

Android for .NET Developers - Location and Maps
In Windows Phone and iOS getting the current position of the device in terms of latitude and longitu...
Android for .NET Developers - Using Web Views
In this article, I'll show a native app that contains a web-based view. The great news is that HTML ...
Android for .NET Developers - Building a Twitter Client
In this article, I'll discuss the features and capabilities required by an Android application to ta...
Developing a Hello World Java Application and Deploying it in Windows Azure - Part II
In this article we will see the steps involved in deploying the WAR created in the first part of thi...
Ref and Out (The Inside Story)
Knowing the power of ref and out, a developer will certainly make full use of this feature of parame...

You might also be interested in the following related blog posts

12 ASP.NET MVC Best Practices read more
MvcContrib working on Portable Areas read more
Business Apps Example for Silverlight 3 RTM and .NET RIA Services July Update: Part 25: ViewModel read more
Afternoon of ASP.NET MVC [16 June] (free Headspring event) read more
ASP.NET MVC and the templated partial view (death to ASCX) read more
ASP.NET MVC in Action talks this week (Texas, Wisconsin) read more
New class: ASP.NET MVC Boot Camp developer training read more
ASP.NET MVC View Engine using VB.NET XML Literals read more
ViewData mechanics and segmentation (excerpt from ASP.NET MVC in Action) read more
ASP.NET MVC Design Gallery and Upcoming View Improvements with the ASP.NET MVC Release Candidate read more

Please login to rate or to leave a comment.