Extra Categories. Getting Started

This topic describes a typical situation for the use of the Extra Categories panel. Assume your application uses the Product and ProductKind business classes which participate in one-to-many relationship.

The following code shows classes to be implemented.

  • c#
  • VB

public class Product : BaseObject
{
  public Product(Session session)
    : base(session)
  {
  }
  public string Name
  {
    get
    {
      return GetPropertyValue<string>("Name");
    }
    set
    {
      SetPropertyValue("Name", value);
    }
  }
  [Association]
  public ProductKind Kind
  {
    get
    {
      return GetPropertyValue<ProductKind>("Kind");
    }
    set
    {
      SetPropertyValue("Kind", value);
    }
  }
}
public class ProductKind : BaseObject
{
  public ProductKind(Session session)
    : base(session)
  {
  }
  public string Name
  {
    get
    {
      return GetPropertyValue<string>("Name");
    }
    set
    {
      SetPropertyValue("Name", value);
    }
  }
  [Association]
  public XPCollection<Product> Products
  {
    get
    {
      return GetCollection<Product>("Products");
    }
  }
}

Public Class Product
  Inherits BaseObject
  Public Sub New(ByVal session As Session)
    MyBase.New(session)
  End Sub
  Public Property Name As String
    Get
      Return GetPropertyValue(Of String)("Name")
    End Get
    Set
      SetPropertyValue("Name", value)
    End Set
  End Property
  <Association> _
Public Property Kind As ProductKind
    Get
      Return GetPropertyValue(Of ProductKind)("Kind")
    End Get
    Set
      SetPropertyValue("Kind", value)
    End Set
  End Property
End Class
Public Class ProductKind
  Inherits BaseObject
  Public Sub New(ByVal session As Session)
    MyBase.New(session)
  End Sub
  Public Property Name As String
    Get
      Return GetPropertyValue(Of String)("Name")
    End Get
    Set
      SetPropertyValue("Name", value)
    End Set
  End Property
  <Association> _
Public ReadOnly Property Products As XPCollection(Of Product)
    Get
      Return GetCollection(Of Product)("Products")
    End Get
  End Property
End Class

Note

Extra Categories is available in the Windows Forms applications only. The complete sample project is available at ExtraCategoriesSample.

extra_categories_3

To accomplish Product_ListView with Product Categories, follow the steps described bellow.

Open the existing XAF solution and add Xafari, Xafari.DockPanels and Xafari.BC modules to the platform agnostic module project.

extra_categories_31

Build project, invoke the Model Editor by double-clicking the Model.DesignedDiffs.xafml file in project.

In the tree view, navigate to the BOModel|...|Product|Categories node, right-click the node and select Add… | Category from the invoked context menu.

For the newly added node, set ModelClass property to the "ProductKind" value, View property to the "Product_LookupListView", RelationCriteria to the "Kind.Oid = '{0:Oid}".

RelationCriteria property uses Criteria Language Syntax to define the desired objects.

extra_categories_4

Add Xafari.Win, Xafari.DockPanels.Win and Xafari.BC.Win modules to the Windows Forms Application Project.

Important

Extra Categories control is displayed within the Dock Panel. Xafari.DockPanels.Win module provides this functionality for the Win application. If the application is operated in Tabbed MDI mode, you need to perform an additional step described in the Dock Panels. Win Tabbed MDI topic.

To see the result, run the application and select Product item in the navigation control. Activate the Categories panel by a special Action as shown in the image below.

extra_categories_5

Now the Product List View shows only those objects that satisfy the RelationCriteria condition defined above.

extra_categories_6

The criterion is calculated on the basis of the current ProductKind object in the Categories pane.

extra_categories_7