Skip to main content

Basic Prism Application for Beginners. (https://msdn.microsoft.com/en-us/library/gg406140.aspx)



The following series of tutorials will help the C# WPF Developer in understanding the PRISM framework.
We will create Step by Step a Report Designer Software (Basic) which will allow the user to design a simple report template.
The purpose behind choosing Report Designer as subject is that we will create different modules which are easily understandable,
lets start :-
Note: - Visual Studio 2012 is used for creating the application. Use this extension for Package Manager console
Download here https://visualstudiogallery.msdn.microsoft.com/27077b70-9dad-4c64-adcf-c7cf6bc9970c

Task 1 : -  Let's create a Simple WPF application and Play with Prism Package,


(1) Create a Simple WPF Application Name it ReportDesigner.



The Solution will look like below

(2) Open the MainWindow.xaml.cs. Rename the "MainWindow" Class to "Shell" by using Refactor.

(3) Rename the MainWindow.xaml in solution explorer 
(4) Open App.xaml and change the StartUpUri="Shell.xaml"
(5) Open Shell.xaml and change the title to "Report Designer".
(6) Hit F5. The applicatio  should show Blank Window with Report Designer as title.
(7) Go to NuGetPackage Manager Console ( If not installed please install it from the link mentioned in the note above)

(8) Use Command Install-package prism
(9) Install UnityExtensions by following command install-package prism.unityextensions
(10) The references in solution explorer will look like this

(11) Now add a Class and Name it to "Bootstrapper". Import Namespaces
using System;
using System.Windows;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.UnityExtensions;
using Microsoft.Practices.Unity; 
(12) Inherit the Bootstrapper Class from UnityBootstrapper. and Override the methods as given below

using System;
using System.Windows;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.UnityExtensions;
using Microsoft.Practices.Unity;
namespace ReportDesigner
{
class Bootstrapper:UnityBootstrapper
{
protected override System.Windows.DependencyObject CreateShell()
{
return new Shell();
}
protected override void InitializeShell()
{
base.InitializeShell();
Application.Current.MainWindow = (Window)this.Shell;
Application.Current.MainWindow.Show();
}
protected override IModuleCatalog CreateModuleCatalog()
{
return base.CreateModuleCatalog();
}
}
}
 (13) In App.xaml delete the StartUpUri tag as we are creating the window from code behind.
And add the copy the following code in App.xaml.cs

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace ReportDesigner
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            Bootstrapper bootStrapper = new Bootstrapper();
            bootStrapper.Run();
        }
    }
}

(14) In Shell.xaml import the following namespace 
Copy the following XAML into Shell.xaml
<Window x:Class="ReportDesigner.Shell"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:prism="http://www.codeplex.com/prism"
        Title="Report Designer" Height="350" Width="525">
    <ItemsControl  prism:RegionManager.RegionName="MainRegion" Name="MainRegion"></ItemsControl>
</Window>
Note : - Till this step we have created a simple application with BootStrapper Class. On Hitting the F5 the application should show the Report Designer window as shown below.

We have not created any module so far. Before we create lets talk about Regions. We have created a Main Region in our Shell.xaml. Regions are basically place holders for views. A module can have multiple views. Below picture is imagination of application what we are trying to achieve using prism.


Comments

Popular posts from this blog

When you work as an IT Engineer never think you are just writing code only, You are also writing a better future of millions by solving their problems. For me development is not my 10 years of sitting in front of computer experience It's the power of developing the correlation between the existing world and  programming world. Developing application either Desktop Based or Azure based from the last ten years seems to me like I am helping a large number of people in doing their business and day to day task smoothly. Just like  as an experience chef make a dish more delicious and consistent without creating kitchen mess. Similarly and experience developer make stunning products easier and simpler to learn and use without much bugs. So with experience one should be a better and calm programmer with better work life balance.