Smart Design. Default View Customisation

When XafariSmartDesignStrategy is utilized, the Smart Design Strategies concept implies that there should be three default Views for each persistent class: List View, Lookup List View, and Detail View. Due to the fact of being the default ones, the models of these Views contain no properties.

smart_design_5

Properties Visibility

This behavior provides the possibility to add only the required properties on the forms, rather than eliminating all superfluous properties from a common set. When a business object exposes a lot of fields, such selective approach is very effective.

To add a property on the default View, apply the special attribute to it in code. The visibility of each property can be set separately for each type of the View. The attributes are listed below:

  • [VisibleInAllView(true)]
  • [VisibleInListView(true)]
  • [VisibleInLookupListView(true)]
  • [VisibleInDetailView(true)]

For instance, the code snippet below demonstrates the VisibleInListView attribute being applied to the Byte, Decimal, and Double properties:

  • c#
  • VB

public class XafarSmartDesignObject : BaseObject
{
  //...
  [VisibleInListView(true)]
  public byte Byte
  {
    get
    {
      return this._byte;
    }
    set
    {
      SetPropertyValue("Byte", ref this._byte, value);
    }
  }
  [VisibleInListView(true)]
  public decimal Decimal
  {
    get
    {
      return this._decimal;
    }
    set
    {
      SetPropertyValue("Decimal", ref this._decimal, value);
    }
  }
  [VisibleInListView(true)]
  public double Double
  {
    get
    {
      return this._double;
    }
    set
    {
      SetPropertyValue("Double", ref this._double, value);
    }
  }
  //...
}

Public Class XafarSmartDesignObject
  Inherits BaseObject
  '...
  <VisibleInListView(True)> _
Public Property [Byte] As Byte
    Get
      Return Me._byte
    End Get
    Set
      SetPropertyValue("Byte", Me._byte, value)
    End Set
  End Property
  <VisibleInListView(True)> _
Public Property [Decimal] As decimal
    Get
      Return Me._decimal
    End Get
    Set
      SetPropertyValue("Decimal", Me._decimal, value)
    End Set
  End Property
  <VisibleInListView(True)> _
Public Property [Double] As double
    Get
      Return Me._double
    End Get
    Set
      SetPropertyValue("Double", Me._double, value)
    End Set
  End Property
  '...
End Class

As a result, the default List View shows three columns (Byte, Decimal, and Double), as shown in the image below.

smart_design_11

It is possible to customize the Detail View and the Lookup List View in the same way via the VisibleInLookupListView and VisibleInDetailView attributes.

Properties Groups

There is a feature to include properties into a specified layout group. It is provided by the SmartDesignGroupAttribute. The following code demonstrates how to add the Integer, Long, and String properties to the default Detail View, the Long and String properties are included into the "Z" group.

  • c#
  • VB

public class XafarSmartDesignObject : BaseObject
{
  //...
  [VisibleInDetailView(true)]
  public Int32 Integer
  {
    get
    {
      return this._integer;
    }
    set
    {
      SetPropertyValue("Integer", ref this._integer, value);
    }
  }
  [VisibleInDetailView(true)]
  [SmartDesignGroupAttribute("Z")]
  public Int64 Long
  {
    get
    {
      return this._long;
    }
    set
    {
      SetPropertyValue("Long", ref this._long, value);
    }
  }
  [VisibleInDetailView(true)]
  [SmartDesignGroupAttribute("Z")]
  public string String
  {
    get
    {
      return this._string;
    }
    set
    {
      SetPropertyValue("String", ref this._string, value);
    }
  }
  //...
}

Public Class XafarSmartDesignObject
  Inherits BaseObject
  '...
  <VisibleInDetailView(True)> _
Public Property [Integer] As Int32
    Get
      Return Me._integer
    End Get
    Set
      SetPropertyValue("Integer", Me._integer, value)
    End Set
  End Property
  <VisibleInDetailView(True)> _
<SmartDesignGroupAttribute("Z")> _
Public Property [Long] As Int64
    Get
      Return Me._long
    End Get
    Set
      SetPropertyValue("Long", Me._long, value)
    End Set
  End Property
  <VisibleInDetailView(True)> _
<SmartDesignGroupAttribute("Z")> _
Public Property [String] As String
    Get
      Return Me._string
    End Get
    Set
      SetPropertyValue("String", Me._string, value)
    End Set
  End Property
  '...
End Class

In the Model Editor, check the ShowCaption flag.

smart_design_12

As a result, the default Detail View shows the Integer, Long, and String properties, as shown in the image below.

smart_design_13

To set the order of the groups displaying, apply DevExpress.Persistent.Base.IndexAttribute and specify its Index. To adjust the order of the groups, use the Model Editor.

IList Properties

The CreateListView attribute is described in the Additional Views topic, but, it is also intended to customize the default Detail View. Apply this attribute to the IList property and don't specify the Id parameter, use the Layout parameter to specify the required columns to display collections. The code snippet below shows how to specify the String and Byte columns for displaying the Objects collection property.

  • c#
  • VB

public class XafarSmartDesignObject : BaseObject
{
  //...
  [NonPersistent]
  [VisibleInDetailView(true)]
  [CreateListView(Layout = "String;Byte", ListViewType = ListViewType.LookupListView)]
  public XPCollection<XafarSmartDesignObject> Objects
  {
    get
    {
      return new XPCollection<XafarSmartDesignObject>(this.Session, null, new SortProperty[] { });
    }
  }
  //...
}

Public Class XafarSmartDesignObject
  Inherits BaseObject
  '...
  <NonPersistent> _
<VisibleInDetailView(True)> _
<CreateListView(Layout := "String;Byte", ListViewType := ListViewType.LookupListView)> _
Public ReadOnly Property Objects As XPCollection(Of XafarSmartDesignObject)
    Get
      Return New XPCollection(Of XafarSmartDesignObject)(Me.Session, Nothing, New SortProperty() { })
    End Get
  End Property
  '...
End Class

The resulting grid is shown in the image below.

smart_design_14

Note

To get acquainted with more advanced customizations, refer to the Xafari.FeatureCenter.XafariSmartDesignGenerator|XafarSmartDesignObject.cs file in the Feature Center demo installed with Xafari. By default, the Feature Center demo is installed in %PUBLIC%\Documents\Xafari Framework v16.1.6011 Demos\FeatureCenter.