Frame.SetView(View) Method

Sets a specified View for the current Frame.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v18.2.dll

Declaration

public bool SetView(
    View view
)
Public Function SetView(
    view As View
) As Boolean

Parameters

Type Name Description
View view

A View object that is set for the current Frame.

Returns

Type Description
Boolean

true, if an old View can be changed by another one; otherwise, false.

Use the SetView method to set a specified View for the current Frame. This method deactivates all Controllers, sets a specified View for the Frame and then re-activates Controllers. Then, if a Template is set for the Frame, the new View is set for this Template (IFrameTemplate.SetView).

Before deactivating and after activating Controllers, the Frame.ViewChanging and Frame.ViewChanged events are raised, respectively. Handle these events to perform specific actions before and after setting a View.

If a View is already set for the Frame, the SetView method replaces it with a new one, raises an old View's View.Closed event, and then disposes it.

To create a View and pass it to the SetView method, use the XafApplication.CreateListView, XafApplication.CreateDetailView and XafApplication.CreateDashboardView methods. Refer to the Ways to Show a View topic for additional information.

The following example demonstrates how to show a View in the main window when a record is selected in a pop-up window. Note that this approach will not work in the MDI mode, since the main window cannot contain a View in this mode.

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
//...
public class ShowPersonController : ViewController {
    public ShowPersonController() {
        PopupWindowShowAction showPersonAction = new 
            PopupWindowShowAction(this, "ShowPerson", PredefinedCategory.View);
        showPersonAction.CustomizePopupWindowParams += 
            showPersonAction_CustomizePopupWindowParams;
        showPersonAction.Execute += showPersonAction_Execute;
    }
    void showPersonAction_CustomizePopupWindowParams(object sender, 
    CustomizePopupWindowParamsEventArgs e) { 
        IObjectSpace newObjectSpace = Application.CreateObjectSpace(typeof(Person));
        e.View = Application.CreateListView(newObjectSpace, typeof(Person), true);
        e.DialogController.AcceptAction.SelectionDependencyType = 
            SelectionDependencyType.RequireMultipleObjects;
    }
    void showPersonAction_Execute(object sender, PopupWindowShowActionExecuteEventArgs e) {
        Person selectedPerson = (Person)e.PopupWindowViewCurrentObject;
        IObjectSpace newObjectSpace = Application.CreateObjectSpace(typeof(Person));
        DetailView personDetailView = Application.CreateDetailView(newObjectSpace, 
            newObjectSpace.GetObject<Person>(selectedPerson));
        personDetailView.ViewEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.Edit;
        e.PopupWindow.Close(true);
        Application.MainWindow.SetView(personDetailView);
    }
}

See Also