Overview
If you are developing a WPF program, you should have heard of the Composite Application Guidance for WPF (PRISM)
All in all, Prism helps you develop complex WPF applications. I hope this series of tutorials will help you.
Since the official version was released last year, it has been nearly half a year. the release of Silverlight 2. prism also began to support Silverlight, and this time it also supports both WPF and Silverlight. in this way, the programming of WPF and Silverlight is unified, and the code porting is more convenient. the latest prism version is prism v2-drop 8. compared with the first version, some changes have taken place. this article introduces the version based on prism v2-drop 8. if you are still using the version of July, you can read the tutorials written by Zhou yinhui.
The three basic concepts are described below.
1. Guided windows form shell
When the WPF program starts, a host container is required. Generally, it is system. Windows. Window. The following is a newly created form.
<Window x:Class="HelloWorldSample.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <Grid> </Grid></Window>
By default, system. Windows. application runs the main form by setting startupuri.
<Application x:Class="HelloWorldSample.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="Window1.xaml"></Application>
Then, with the addition of the prism framework, the method for running the main form is changed. prism requires a bunch of tasks before running the form to pave the way for what the framework can do. so we need to remove startupuri and manually start the form. prism uses a class named bootstrapper as the guiding program. Here, no matter what he does, we only know that he has played a guiding role in the program.
Through bootstrapper guidance, this form is no longer just a simple form. This form can also be calledShellIt can also be understood as a shell.
2. added content region Region
Take the master page in Asp.net as an example.
Before creating a website, you must first layout the template. You should be familiar with the template. The purpose is to use the master page as a container and then add content in the defined contentplaceholder area.
Generally, after a master page is defined, it must be applied to other pages.
This is a good practice. It can be implemented using a WPF Program (refer to this Article), but it is troublesome. there is an essential difference between a web program and a client program. The web is stateless and the client program has no such problems.
HypothesisThe Web is stateful (assuming it is OH). It can be replaced by a user control, and the ASPX page is used as the master page to define the container and insert the user control into it.
In this way, the current Ajax program should be very popular.
Back to the topic, the prism framework passesAdditional attributesToShellDefine a custom region. The title is an additional content area. The following code is used,
A region is defined for itemscontrol by attaching an attribute, and itemscontrol becomes the container of this region.
The region and the contentplaceholder on the Asp.net master page have the same meaning, but the implementation method is different.
<Window x:Class="HelloWorldSample.Shell" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:cal="http://www.codeplex.com/CompositeWPF" Title="Composite Application Library Sample" Width="400" Height="300"> <ItemsControl cal:RegionManager.RegionName="MainRegion"/></Window>
Note: The regionmanager append regionname registration function is provided by bootstrapper before the form is instantiated.
3. Module of the split Module
After the region content area is defined, you can load User Controls of different modules in region. each module has different functions. A powerful application is composed of different modules. split different functions of an application into different small modules for development, significantly reducing the complexity.
Well, here are three points.
1. Shell, main application container, cornerstone of prism Function
2. region, which is also called the content area, provides the view (User Control) required for loading each module)
3. Module: component module of the program.
With the above three concepts, we can start the prism journey. If you are not clear about the above concepts, it doesn't matter. I will introduce it later. If a friend who is already using this framework finds an error, please point it out. In the next article, let's explore the use of region.
Http://www.cnblogs.com/Clingingboy/archive/2009/01/06/prism_part1.html