Windows and Frames
- 4 minutes to read
Windows automatically generated by the eXpressApp Framework are defined by two objects: a control called Template and an abstract entity called Window. Similarly, lookup windows and embedded List Views are represented by a Template and Frame pair. A Window or Frame, in contrast to a Template, does not contain information on what controls must be located on it. Windows and Frames only include the information concerning their functions in the eXpressApp Framework applications. This topic provides detailed information about these abstract UI entities. For information on Templates, refer to the Templates topic.
Windows and Frames Overview
A Frame is defined by the Frame class; a Window, by the Window class. The Frame class is the base class of the Window. The difference between these classes is that a Window is an independent UI element, while a Frame has a parent. For instance, a main form and detail forms are defined by the Window class. A lookup editor's drop down window and embedded List Editor are defined by the Frame class.
XAF does not use Window class directly. In fact, Windows Forms and ASP.NET Web applications create the WinWindow and WebWindow class instances respectively. These are Window class descendants. You can use the Window type in the UI independent code, and cast it to the WinWindow and WebWindow types in the UI specific code.
The base functions of Windows and Frames are:
Both of them serve as a site for a View.
Business applications are mainly intended to view and edit data. That's why the default eXpressApp Framework application contains only Windows with Views. A Window itself in eXpressApp Framework is not useful to you. When building applications, you primarily refer to a Window to access its View. To do this, use a Window's or Frame's Frame.View property. When implementing a custom feature, you may need to set another View to a particular Window. To do this, use one of the Frame.SetView method overloads.
Both of them allow you to perform custom actions when they are being created or destroyed.
When Windows and Frames are being created, they locate all appropriate Controllers and register them in their Frame.Controllers collection. Controllers, in turn, provide events that let you execute specific actions when creating or deleting the owner Window or Frame. Controllers are not shared between different Windows/Frames. An Controller instances are created for each Window and Frame individually.
Windows (Frames) are displayed in a UI via Templates. A Template displays both the actions of the window's Controllers and a View. You can access the template via the window's Window.Template (Frame.Template) property, and customize this template. For information on template customization, refer to the Template Customization topic.
Access Windows and Frames
When a Window or a Frame is created, it finds all Controllers related to it. To access them, you can use the desired Window's or Frame's Frame.Controllers property. However, in most cases you will need to perform the opposite operation. Since you will write code within Controller classes, you will need to access the current Window or Frame that owns a particular Controller. To learn how to do this, see the following list.
Window Controllers are objects that allow executing custom code when Windows are being created and destroyed. That is, you can override their protected OnWindowChanging method, handle the Controller.Activated and Controller.Deactivated events. In these event handlers, you can access the corresponding Window using the Controller's WindowController.Window property.
View controllers are objects that allow executing custom code when Frames are being created and destroyed. That is, you can handle their Controller.Activated and Controller.Deactivated events. In these event handlers, you can access the corresponding Frame using the Controller's Controller.Frame property. Of course, you can cast the Frame to the Window class, if the currently processed Frame is a Window.
If a feature cannot be implemented via a Window Controller or a View Controller, you can create a custom controller by declaring a Controller class descendant. Every time a Frame is created, XAF calls each Controller's OnFrameAssigned method. Override this method to access the Frame or Window that is being created.