in
Forums
Blogs
Files
Devexpress.Com
ClientCenter
DevExpress Channel

Windows Forms

May 2006 - Posts

  • Visual inheritance support for complex controls.

    As all of you probably know, when .NET was released, Microsoft introduced support for visual inheritance - VI. There are a number of articles on the web which praise VI, but this blog entry discusses its limitations when used with complex controls. To do so, we'll start by creating a new control which contains a public collection.

    public class MyControl1 : Control {
            Collection items;
            public MyControl1() {
                items = new Collection();
            }
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            public Collection Items {
                get { return items; }
            }
    }
    }

    Start VS2005. Create a new windows application, and add the above class to it. After rebulding, you will see MyControl1 at the top of the toolbox. Add MyControl1 to form1, and set MyControl1.Modifiers to public and take a look at the Items collection

    Note that we can change it without any limitations. Now create a descendant of form1 successor via visual inheritance(Project-> Add -> NewItem -> Inherited Form). Let’s look at the Items collection in the descendant

    We can not change collections in the successor, since this is disabled by Microsoft. What is the reason for this? Collections cannot be serialized correctly in VI descendants.

    Now lets talk about complex controls. By complex I mean a control which contains a public collection that should serialize correctly at designtime. VI is a powerful thing for rapid UI development but you should take into account the limitation's of collection serialization. Here are a set of recomendations you should follow when creating VI descendants of DX controls. 

    1. There are no known limitations for XtraEditors when using VI
    2. You should not change the XtraLayoutControl's layout in a descendant (all changes will be lost!) A workaroud is to split the form’s layout into several parts and create a separate XtraLayoutControl for each one. This approach is shown in the XtraLayoutMainDemo. The topmost part (which contains Save/Load buttons) for all demo modules is inherited.
    3. In VI descendants Moving or Removing inherted columns in the collection can cause problems, you can only safely Add columns to the XtraGridControl. But there are no limitations on changing the properties of existing columns.
    4. You cannot remove inherited items from XtraBars.
    5. VI for inherted collections is not supported by the TreeList, VerticalGrid, PivotGrid, XtraSheduler and XtraCharts.  

    The rules above can be summarized by a single general rule: Changing collections in VI descendants leads to problems and you should avoid changing collections in descendants.

    Let's now discuss some typical examples of correct and incorrect usage of VI.

    XtraBars
    Incorrect:
    Arrange item links on toolbars in the successor.
    Correct: Add all bar items in the base control, place them on toolbars programmatically.
    XtraGrid
    Incorrect:
    Customize XtraGrid in the base form.
    Correct: Place an empty XtraGrid on the base form and bind it to data and create columns in successors.
    XtraLayout
    Incorrect:
    Customize layout in the successors.
    Correct: Split the form's layout into the several logical square segments and create a separate XtraLayout control for each of them. Customize each layoutControl in the form where is it was created.

  • XtraLayoutControl feature preview: Expanded groups

    The XtraLayoutControl has LayoutControlGroup items which represent Group boxes. In v6.2.x the LayoutControlGroup will be able to expand / collapse its client area. Let’s call this feature – expanded groups.  This article demonstrates how to unlock the Expanded groups feature in the XtraLayoutControl v6.1.4.

    Warning: The expanded groups feature will only be officially supported from v6.2.x. The names of properties and methods in the code below are subject to change.

    Expanded groups functionality will be implemented in two additional fields in the LayoutControlGroup: Expanded, IsExpandedButonVisible. To unlock these properties you should inherit from the XtraLayoutControl and LayoutControlGroup as below

        class MyLayoutGroup : LayoutControlGroup {

            protected override LayoutGroup CreateLayoutGroup() {

                return new MyLayoutGroup();

            }

            public bool IsExpandButtonVisible {

                get {

                    return isExpandedButtonVisibleInternal;

                }

                set {

                    isExpandedButtonVisibleInternal = value;

                    shouldResetBorderInfo = true; ComplexUpdate();

                }

            }

            public bool IsExpanded {

                get { return Expanded; }

                set { Expanded = value; }

            }

        }

        class MyLayoutControl : LayoutControl {

            protected override LayoutControlGroup CreateRoot() {

                return new MyLayoutGroup();

            }

        }

    Here are steps by step instruction to unlock the expanded groups feature.

    -         Create a new WindowsApplication form the VS2005.

    -         Add a new class to the WindowsApplication.

    -         Insert MyLayoutGroup and MyLayoutControl code to the new created file

    -         Rebuild

    -         Find MyLayoutControl in a WindowsApplication1Componets tab in the Toolbox.

     

    If the above steps are completed successfully, you will be able to place a         MyLayoutControl on the form and set its IsExpandButtonVisible to true for LayoutGroups. The result is shown below.

     

     

     

     

    The benefits of this feature are evident. You can replace all the NavBar controls in your application with the XtraLayoutControl and take advantage of all the XtraLayoutControl's features:

    -         runtime layout serialization

    -         runtime user customization

    -         appropriate and customizable taborder

    -         total flexibility in tuning the layout (padding, spacing, alignment)

    And many other cool features

     

    The expanded groups feature is currently being tested. Here are the known problems

    -         Not supported by skin based paintstyles

    -         DesignTime support is not fully implemented

     

    Feel free to send us your ideas, suggestions and bugs related to this coming feature.

     

Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED