The requested page is not available for the requested platform. You are viewing the content for Default platform.

How to: Show a Custom Window with an Embedded XAF View

  • 3 min to read

The most recommended way to show a non-XAF window in a WinForms application is to embed custom controls in an XAF form (e.g. DashboardView) using custom view items. However, if it is not appropriate for your case, you can embed XAF views in a custom window by creating views and adding their controls to the form. In the simplest case, it is sufficient to create a View instance, configure it as required, call its View.CreateControls method, and add its Control to the form.

CustomWindowWithXAFView

In this example, the custom window with the embedded XAF ListView is invoked when an Action Execute event occurs. Create a new ViewController descendant and add a new SimpleAction in its constructor. In the Action's Execute event handler, create a new instance of a custom NonXAFForm which is a form object. The LayoutControl control is created to correctly place custom controls on the layout. The XAF ListView control is created using the XafApplication.CreateListView method and its controls are generated using the CreateControls method. Set the controls as layout items and invoke the window using the Form.ShowDialog method.

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.BaseImpl;
using DevExpress.XtraLayout;
using System.Windows.Forms;

namespace SolutionWithCustomWindow.Module.Win.Controllers {
    public partial class LinkViewController : ViewController {
        public LinkViewController() {
            SimpleAction showWindowAction = new SimpleAction(this, "Show Window", DevExpress.Persistent.Base.PredefinedCategory.View);
            showWindowAction.ImageName = "ModelEditor_Views";
            showWindowAction.Execute += new SimpleActionExecuteEventHandler(showWindowAction_Execute);
        }
        void showWindowAction_Execute(object sender, SimpleActionExecuteEventArgs e) {
            NonXAFForm form = new NonXAFForm();
            form.Text = "Form with the XAF ListView";

            LayoutControl layoutControl = new LayoutControl();
            layoutControl.Dock = System.Windows.Forms.DockStyle.Fill;
            form.Controls.Add(layoutControl);

            LayoutControlItem item1 = layoutControl.Root.AddItem();
            TextBox textBox1 = new TextBox();
            item1.Text = "Company";
            item1.Control = textBox1;

            DevExpress.ExpressApp.View listView = Application.CreateListView(Application.CreateObjectSpace(), typeof(Person), false);
            listView.CreateControls();
            LayoutControlItem item2 = layoutControl.Root.AddItem();
            item2.Text = "Persons";
            item2.Control = (Control)listView.Control;

            form.ShowDialog();
        }
    }
}

If it is necessary to show a toolbar with Actions and manage the View's behavior using the Controllers, create a nested Frame's instance, place a View in it, and add the Frame's Template to the form.

void showWindowAction_Execute(object sender, SimpleActionExecuteEventArgs e) {
    NonXAFForm form = new NonXAFForm();
    //...
    Frame frame = Application.CreateFrame(TemplateContext.NestedFrame);
    frame.CreateTemplate();
    frame.SetView(listView);
    LayoutControlItem item2 = new LayoutControlItem();
    item2.Parent = layoutControl.Root;
    item2.Text = "Persons";
    item2.Control = (Control)frame.Template;
    form.ShowDialog();        
}

CustomWindowWithXAFView_NestedFrame

See Also