Click here to Skip to main content
13,147,182 members (28,026 online)
Click here to Skip to main content
Add your own
alternative version


11 bookmarked
Posted 23 Sep 2012

How to Show Usual Winform as View in XAF

, 7 May 2013
Rate this:
Please Sign up or sign in to vote.
XAF is a good framework that facilitates software making, but as it provides many benefits, there is the limitation that you have to deal with, one of them is placing fully customized form in a view


This tip will show you how to put your usual winforms (designed now) in a "view" which is the main container of XAF UI.

There are official guides as to how to show fully customized forms in XAF, but placing an Action over a view and showing window from there is the core of these guides.

The main disadvantage of this approach is that we cannot call it from the navigation menu and have to call it from ToolBar or RibbonBar. It doesn't make good sense for end users.


I challenge the XAF dev guys and myself to find a generic solution for custom and complex form designing in XAF.

On the one hand, the benefits of XAF are hard to ignore and on the other hand, its limitations and rules are too maddening.

This tip is a partial result of this challenge.

Using the Code

The first step is creating controller that handles navigation pane behaviors. Controllers are classes to change XAF application's flow and implement custom end-user interaction.

This controller will change the default behavior of specific navigation item and show our custom view.

The mentioned controller must inherit from DevExpress.ExpressApp.SystemModule.ShowNavigationItemController.

For rewriting default behavior, we need override ShowNavigationItem method.

 protected override void ShowNavigationItem(SingleChoiceActionExecuteEventArgs e)
// if section, filter navigation node
           if ((e.SelectedChoiceActionItem != null)
          && e.SelectedChoiceActionItem.Enabled.ResultValue
          && e.SelectedChoiceActionItem.Id == "the id of navigation node ")

               Frame workFrame = Application.CreateFrame(TemplateContext.ApplicationWindow);
               View v = new BaseView(typeof(Custom Form ),"Caption","ID of View");
               e.ShowViewParameters.TargetWindow = TargetWindow.Default;
               e.ShowViewParameters.CreatedView = v;
               return;//Cancel the default processing for this navigation item.


The above code causes specified navigation item, shows our custom view.

The next step is defining the BaseView class.

class BaseView : DevExpress.ExpressApp.View
       Form frm;
       public BaseView(Type Frm, string Caption, string ID)
           : base(true)
           if (Frm == null)
               throw new Exception("Form is null or invalid");
           if (!Frm.IsSubclassOf(typeof(Form)))
               throw new Exception("Form is null or invalid");
           frm = (Form)Activator.CreateInstance(Frm);

           this.Id = ID;
           this.Caption = Caption;
           this.CurrentObject = null;

       protected override object CreateControlsCore()
           frm.TopLevel = false;
           frm.FormBorderStyle = FormBorderStyle.None;
           frm.Visible = true;
           return frm;

       protected override void LoadModelCore()
          // throw new NotImplementedException();

       protected override void RefreshCore()
          // throw new NotImplementedException();

       protected override void SaveModelCore()
           //throw new NotImplementedException();

In the above code, we inherit from View class (the base of XAF views) and implement our custom rules.

The constructor gets 3 parameters, the first parameter is custom form to show, the second and third are caption and id of generated view.

The magic is in this code.

frm.TopLevel = false;

That allows window nest in a control.

Points of Interest

This solution has solved my problem, but further development can be done to create stronger relation to XAF rules, specially in LoadModelCore, RefreshCore, SaveModelCore in BaseView class.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Ehsan yazdani rad
Software Developer (Senior) Independent
Iran (Islamic Republic of) Iran (Islamic Republic of)
I start developing software when I was 9 with my commodore 64.

Programming Designer and Quality Supervisor.

Specializing in Web business solutions specially in sale and distribution industry.

Wrote my first “real” program on a commodore 64 which was a shooting game.

A few Highlights:
C#, VB.NET , Win & Web
JavaScript and popular library such jquery
Sql Server

You may also be interested in...


Comments and Discussions

Questionwhere is the sample? Pin
RomanRapido9-Jul-15 20:18
memberRomanRapido9-Jul-15 20:18 
GeneralGreat Work! Pin
belzer2-Oct-13 14:32
memberbelzer2-Oct-13 14:32 
QuestionObject reference not set to an instance of an object Pin
whizkid6-Sep-13 1:00
memberwhizkid6-Sep-13 1:00 
Questionexample Pin
VemotionA21-Aug-13 1:56
memberVemotionA21-Aug-13 1:56 
AnswerRe: example Pin
Ehsan yazdani rad27-Aug-13 1:56
memberEhsan yazdani rad27-Aug-13 1:56 
GeneralRe: example Pin
dauciunas3-Dec-13 0:44
memberdauciunas3-Dec-13 0:44 
GeneralRe: example Pin
Member 1006519916-Feb-15 1:26
memberMember 1006519916-Feb-15 1:26 
QuestionIs RightToLeft possible for XAF? Pin
Ehsan Moshiri10-Jun-13 17:45
memberEhsan Moshiri10-Jun-13 17:45 
AnswerRe: Is RightToLeft possible for XAF? Pin
Ehsan yazdani rad30-Jun-13 21:09
memberEhsan yazdani rad30-Jun-13 21:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170915.1 | Last Updated 8 May 2013
Article Copyright 2012 by Ehsan yazdani rad
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid