This project is read-only.
This page shows step to create your own application. In case when it’s not specified enough you can find in the repository the living and breathing example application. It shows some basic capabilities, but without specific usage:
  • It has main empty application window.
  • There are shown information view when application starts.
  • Default menu with basic actions and forms available straight from the platform (like logging information or color theme).
  • Basic functionalities like information about application or changing application options.
  • Some additional functionalities (not available from the platform) like displaying content of the files on the form.
Example application can be run by using WpfRcp.Application.sln and running the WpfRcp.Application.UI project.

Quick start

To build your own application based on WPF RCP you should go by the following instructions.

Project references

First you should create your own VS solution as Windows WPF Application (ex. MyWpfRcpApplication.sln) and add the following references:
  • Projects (code from the repository): WpfRcp, WpfRcp.Controls, WpfRcp.Core, WpfRcp.PropertyModel, WcfRcp.Logging.EnterpriseLibrary
  • Libraries (found in /lib folder): Caliburn.Core, Caliburn.PresentationFramework, Microsoft.Practices.Composite, Microsoft.Practices.Composite.Presentation, Microsoft.Practices.EnterpriseLibrary.Common, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Microsoft.Practices.ServiceLocation
  • .Net references: PresentationCore, PresentationFramework, UIAutomationProvider, WindowsBase

Application adjustments

The easiest way to create your application is to copy files and structure form example application and make few changes.

Resources
If you have icon for your application you should put it to the /Resources/Images and delete the User.ico icon (unless you want to use it in your application). After that you may want to change the link to the icon in the /Resources/Common.xaml file for it to point to the right one.
Secondly you may want to change the resources (in the /Properties/Resources.resx file) to reflect your name and yours project data. Those information are then used for example in /Views/Controls/AboutView.xaml.

Application Bootstrapper
For the application to work there should be two classes inherited: BootstrapperBase and ApplicationBase. It's best to copy the code from example application classes: WpfRcpApplicationBootstrapper and WpfRcpApplication (by also changing the names of the class and constructors) and removing some lines:

MyApplicationBootstrapper:
  • RegisterViews method should only have the following code:
  base.RegisterViews();
  Container.Register<IAboutView, AboutView>();
  Container.Register<AboutViewPresentationModel, AboutViewPresentationModel>();
  
  var registry = Container.Resolve<IRegionViewRegistry>();
  registry.RegisterViewWithRegion(RegionNames.AboutRegion, typeof(IAboutView));

  Container.Register<ILoggerService, EntLibLoggerService>(LifetimePolicy.Singleton);
  Container.Register<WpfRcp.Views.ILoggerView, EntLibLoggerView>(LifetimePolicy.Singleton);
  • SetRcpSettings should point to the images for your application – in the example application they point to the User.ico image.
  • ConfigureRegionAdapterMappings method should be deleted.

MyApplication:
  • Contructor should have only the line:
Resources.MergedDictionaries.Add(new Resources.Common());
  • Rest of the code should point to the MyApplication and MyApplicationBootstrapper classes.

Customized modules

At this point your application has the following properties:
- Empty main application window.
- Information view when application starts.
- Default menu.
- Basic functionalities like information about application or changing application options.

If you want to add your application own behavior you need to create a module. To see the example you should look at WpfRcp.Modules.Panels in example application.
Application is build based on template:
- Menu at the top
- Tab panels at the right
- Bottom panel
- Left options
- Main window

Building a module
To build a module you should create new project (MyApplication.Modules.MySpecifiedFunctionality) and create MySpecifiedFunctionalityModule class:

[Module(ModuleName = "MySpecifiedFunctionalityModule")]
internal sealed class MySpecifiedFunctionalityModule : ModuleBase
{
   ...
}

It should inherit from ModuleBase and have the attribute Module. To make it work you don’t have to reference this project from UI project, the attribute makes sure it will be visible when you compile the module to the same place. So it’s best to make all your project compile to the same folder (for example /bin in the solution folder).
In the MySpecifiedFunctionalityModule there are mechanisms to add controls to the right and main panel and also specified items to the menu.

Creating controls and adding them to the right panel

To follow the Prism MVVM pattern to create the control you need three things: interface for the view control, actual control and presentation model corresponding to a view. There should be some naming convention applied: control should be named with the suffix View (ex. MyTabView), the interface name is similar (ex. IMyTabView) and presentation model with PresentationModel suffix (ex. MyTabPresentationModel). Below you can see example codes.

Control interface (in Views folder):
public interface IMyTabView
{
    MyTabPresentationModel Model { get; set; }
}

Presentation model (in Views/Presenters folder):
public class MyTabPresentationModel : PresenterBase<IMyTabView>
{
    public MyTabPresentationModel(IMyTabView myTabView)
    {
        View = myTabView;
        View.Model = this;
    }
}

Control (in Views/Controls folder):
public partial class MyTabView : UserControl, IMyTabView
{
    public MyTabView()
    {
        InitializeComponent();
    }

    public MyTabPresentationModel Model
    {
        get { return (MyTabPresentationModel)DataContext; }
        set { DataContext = value; }
    }
}

Specified behavior should be implemented in presentation model, and the view in tab control.
To display this tab on the right panel there should be code in the RegisterViews method of the MySpecifiedFunctionalityModule class:

protected override void RegisterViews()
{
    Container.Register<IMyTabView, MyTabView>();
    Container.Register<MyTabPresentationModel, MyTabPresentationModel>(LifetimePolicy.Singleton);

    var myTabPresentationModel = Container.Resolve<MyTabPresentationModel>();

    var viewItem = new ViewItem();
    viewItem.Visual = myTabPresentationModel.View;
    viewItem.Name = WpfRcp.Modules.Panels.Properties.Resources.Displaying;

    m_WorkbenchService.Add(viewItem, DockStyle.RightPanel); // <-- this adds the control to the right panel
}

To make this work you should fill the m_WorkbenchService by the constructor injection (see the example application).

Displaying controls in the main panel
To display control in the main panel you should follow the scenario described earlier and create the control that you want to display. Then, in the RegisterViews method or as a result of some action:

The code that puts control MyTab to the main panel:
var workbenchItem = new DocumentItem("Some header", myTabPresentationModel.View);
m_WorkbenchService.Add(workbenchItem); 

The same as before, to make this work you should fill the m_WorkbenchService by the constructor injection.

Adding items to the menu

Adding items to the menu is as simple as the command (in the RegisterViews method):
// Adding a group
var group = m_menuRegistry.RegisterMenuItemGroup("MyGroupName", ApplicationConstants.Menus.Level1.File);
group.Position = 50;
group.Text = "GroupText";

//Adding menu to the group
var menuItem = m_menuRegistry.RegisterMenuItem("MyMenuName", "MyGroupName", MyCommand);
menuItem.Position = 0;
menuItem.Text = "MyMenuText";

This will add the group to the File tab and menu item to the newlz added group. For item to work (have some behavior) there should be command registered (MyCommand in the code) that point to the appropriate delegate.

Last edited Mar 7, 2013 at 1:20 PM by coldfusion, version 12

Comments

No comments yet.