Check Action. Getting Started

This topic provides a step-by-step guide to start using the Check Action features. The code snippet below declares the CheckActionObjects persistent class that will be used for demonstration purposes.

  • c#
  • VB

[DefaultClassOptions]
public class CheckActionObjects : BaseObject
{
  public CheckActionObjects(Session session)
    : base(session)
  {
  }
  public override void AfterConstruction()
  {
    base.AfterConstruction();
  }
  private string _nameProperty;
  private string _logProperty;
  public string NameProperty
  {
    get
    {
      return _nameProperty;
    }
    set
    {
      SetPropertyValue("NameProperty", ref _nameProperty, value);
    }
  }
  [Size(SizeAttribute.Unlimited)]
  [ModelDefault("AllowEdit", "False")]
  public string LogProperty
  {
    get
    {
      return _logProperty;
    }
    set
    {
      SetPropertyValue("LogProperty", ref _logProperty, value);
    }
  }
}

<DefaultClassOptions> _
Public Class CheckActionObjects
  Inherits BaseObject
  Public Sub New(ByVal session As Session)
    MyBase.New(session)
  End Sub
  Public Overrides Sub AfterConstruction()
    MyBase.AfterConstruction()
  End Sub
  Private __nameProperty As String
  Private __logProperty As String
  Public Property NameProperty As String
    Get
      Return __nameProperty
    End Get
    Set
      SetPropertyValue("NameProperty", __nameProperty, value)
    End Set
  End Property
  <Size(SizeAttribute.Unlimited)> _
<ModelDefault("AllowEdit", "False")> _
Public Property LogProperty As String
    Get
      Return __logProperty
    End Get
    Set
      SetPropertyValue("LogProperty", __logProperty, value)
    End Set
  End Property
End Class

Implement this class in the platform-agnostic module. Then invoke the Add New Item dialog, choose DevExpress XAF, add a new View Controller to the project, and name this controller CheckActionObjectsViewController.

check_action_2

Set the Controller's properties as follows: TargetViewType is DetailView and TargetObjectType is CheckActionObjects. The image below demonstrates the appropriate Solution Explorer and Properties windows.

check_action_3

Build the project, invoke the Module Designer, drag XafariModule from the Toolbox to the Modules panel, and rebuild the project.

check_action_4

In the same way, add XafariWinModule to the WinApplication project and add XafariWebModule to the WebApplication project.

In the Solution Explorer, double-click the CheckActionObjectsViewController item to invoke the Controller's Designer, add the CheckAction object from the Xafari tab, and set its Caption and Id properties to the "CheckAction" value. The image below shows the CheckActionObjectsViewController Designer with CheckAction.

check_action_5

Subscribe to the CheckedChanged and Execute Action's events:

check_action_6

Modify the CheckActionObjectsViewController.cs file as follows. Add the _markChecked field and the CheckUncheckChanged method to the CheckActionObjectsViewController class; then implement the checkAction1_Execute event handler. The code snippet below demonstrates how the class should look like after the changes are applied:

  • c#
  • VB

public partial class CheckActionObjectsViewController : ViewController
{
  private bool _markChecked = true;
  protected void CheckUncheckChanged(CheckAction objCheckAction)
  {
    objCheckAction.Checked = _markChecked;
    _markChecked = !_markChecked;
  }
  //...
  private void checkAction1_Execute(object sender, SimpleActionExecuteEventArgs e)
  {
    var checkUncheck = (CheckAction)sender;
    CheckUncheckChanged(checkUncheck);
  }
}

Public Partial Class CheckActionObjectsViewController
  Inherits ViewController
  Private __markChecked As Boolean = True
  Protected Sub CheckUncheckChanged(ByVal objCheckAction As CheckAction)
    objCheckAction.Checked = __markChecked
    __markChecked = Not __markChecked
  End Sub
  '...
  Private Sub checkAction1_Execute(ByVal sender As Object, ByVal e As SimpleActionExecuteEventArgs)
    Dim checkUncheck = CType(sender, CheckAction)
    CheckUncheckChanged(checkUncheck)
  End Sub
End Class

As you can see in the code above, the checkAction1_Execute method changes the CheckAction.Checked property and, thereby, triggers the CheckedChanged event. Add the LogTrace method to the CheckActionObjectsViewController class and implement the checkAction1_CheckedChanged event handler as follows:

  • c#
  • VB

public partial class CheckActionObjectsViewController : ViewController
{
  //...
  private void LogTrace(string message)
  {
    ((CheckActionObjects)View.CurrentObject).LogProperty = message + "\r\n" + ((CheckActionObjects)View.CurrentObject).LogProperty;
  }
  //...
  private void checkAction1_CheckedChanged(object sender, EventArgs e)
  {
    var checkUncheck = (CheckAction)sender;
    checkUncheck.Caption = checkUncheck.Checked ? "Checked" : "Unchecked";
    LogTrace(checkUncheck.Checked ? string.Format("The 'CheckAction' is checked.") : string.Format("The 'CheckAction' is unchecked."));
  }
}

Public Partial Class CheckActionObjectsViewController
  Inherits ViewController
  '...
  Private Sub LogTrace(ByVal message As String)
    CType(View.CurrentObject, CheckActionObjects).LogProperty = message + "" + vbCrLf + "" + CType(View.CurrentObject, CheckActionObjects).LogProperty
  End Sub
  '...
  Private Sub checkAction1_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
    Dim checkUncheck = CType(sender, CheckAction)
    checkUncheck.Caption = If(checkUncheck.Checked, "Checked", "Unchecked")
    LogTrace(If(checkUncheck.Checked, String.Format("The 'CheckAction' is checked."), String.Format("The 'CheckAction' is unchecked.")))
  End Sub
End Class

To see the result, run the WinForms or ASP.NET application, select the Check Action Object item in the navigation control, and click the New Action. In the invoked Detail View, click CheckAction several times and see that it supports two different states: Checked and Unchecked.

Win:

check_action_7

Web:

check_action_8