开发者

Is there a concept of a master page (like in asp.net) for WPF?

I've started a WPF (web-based) application and开发者_运维知识库 it has multiple pages. I want to implement the concept of a Master page in WPF, so that when I make changes in the design/layout of one page then all the others pages will follow suit without all the copy and paste.


I don't think the concept of Master Page is valid in WPF basically because there are no pages. In WPF exists styles, templates and DataTemplates. Not only that, using the DockPanel and other containers you can achieve most of the functionality provided by ASP.NET Master Pages.

In any case, if you still the need of the master pages, I suggest check this article: http://www.codeproject.com/KB/WPF/WPFMasterPageControl.aspx

HTH


The WPF Magellan Framework (open source) have Master pages (and other several interesting concepts)

Is there a concept of a master page (like in asp.net) for WPF?


use a master view and put a ContentControl with the master view, then bind the Content property to a property on your data context and set the property to an instance of a UserControl which will then populate the content section.

I will provide some more detail later


You can use global styles to apply a consistent look and feel across your app. As for functionality of a master page. Look at the MVVM pattern. Microsoft has an implementation but there are others.

It let's you define a shell in xaml and specify regions that act sort of like content placeholder's in ASP.NET. Then you write user controls that get loaded into those regions in the shell. It's a lot more involved than using a master page with ASP.NET though. But conceptually similar as far as screen layout goes.

As always, not a bad place to start getting an overview http://en.wikipedia.org/wiki/MVVM

Tons more stuff on MSDN and so on.


You can use Prism open source framework (downloadable from: patterns & practices: Prism) and using that you can create a Shell Window, which can be used as the MainWindow for your WPF project. Then, inside your Shell window, you can create Regions and inject your views into those regions.

Below is what MSDN has to say about Shell (See: Composing the User Interface using Prism):

The shell is the application root object that contains the primary UI content. In a Windows Presentation Foundation (WPF) application, the shell is the Window object. In a Silverlight application, the shell is the RootVisualUserControl. The shell plays the role of a master page providing the layout structure for the application. The shell contains one or more named regions where modules can specify the views that will appear. It can also define certain top-level UI elements, such as the background, main menu, and toolbar. The shell defines the overall appearance of the application. It might define styles and borders that are present and visible in the shell layout itself, and it might also define styles, templates, and themes that will be applied to the views that are plugged into the shell. Typically, the shell is a part of the WPF application project or primary Silverlight project. The assembly that contains the shell might or might not reference the assemblies that contain the views to be loaded in the shell's regions.

Basic Prism Shell structure with WPF:

Is there a concept of a master page (like in asp.net) for WPF?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜