Click here to Skip to main content
Click here to Skip to main content
Go to top

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

Introduction

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.

Background

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");
                workFrame.SetView(v);
                e.ShowViewParameters.TargetWindow = TargetWindow.Default;
                e.ShowViewParameters.CreatedView = v;
                return;//Cancel the default processing for this navigation item. 
               
            }
            base.ShowNavigationItem(e);
        }  

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.

License

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

Share

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
PHP
Delphi
Sql Server

Comments and Discussions

 
GeneralGreat Work! Pinmemberbelzer2-Oct-13 14:32 
QuestionObject reference not set to an instance of an object Pinmemberwhizkid6-Sep-13 1:00 
Questionexample PinmemberVemotionA21-Aug-13 1:56 
AnswerRe: example PinmemberEhsan yazdani rad27-Aug-13 1:56 
GeneralRe: example Pinmemberdauciunas3-Dec-13 0:44 
QuestionIs RightToLeft possible for XAF? PinmemberEhsan Moshiri10-Jun-13 17:45 
AnswerRe: Is RightToLeft possible for XAF? PinmemberEhsan yazdani rad30-Jun-13 21:09 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 8 May 2013
Article Copyright 2012 by Ehsan yazdani rad
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid