Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Collapse]eXpressApp Framework
 [Expand]Fundamentals
 [Expand]Getting Started
 [Collapse]Concepts
  [Expand]Application Solution Components
   Client-Side Mobile Application
  [Expand]Business Model Design
  [Expand]Application Model
  [Expand]UI Construction
  [Expand]Extend Functionality
  [Expand]Data Manipulation and Business Logic
  [Expand]Security System
  [Expand]Localization
  [Expand]System Module
  [Collapse]Extra Modules
   [Expand]Audit Trail Module Overview
    Business Class Library Customization Module
    Chart Module
    Clone Object Module
   [Expand]Conditional Appearance Module Overview
   [Expand]Dashboards Module
    File Attachments Module Overview
    HTML Property Editor Module
    Localization Module Overview
   [Expand]Notifications Module
    KPI Module
   [Expand]Maps Module
   [Expand]Pivot Chart Module
    Pivot Grid Module
   [Expand]Reports V2 Module
   [Expand]Reports Module (Obsolete)
   [Expand]Scheduler Module
    Script Recorder Module
   [Collapse]State Machine Module
     State Machine Module Overview
     User-Defined State Transitions Specified at Runtime
     Predefined State Transitions Created in Code
   [Expand]TreeList Editors Module
   [Expand]Validation Module
    View Variants Module
   [Expand]Workflow Module
  [Expand]Debugging, Testing and Error Handling
  [Expand]Filtering
  [Expand]Application Life Cycle
 [Expand]Design-Time Features
 [Expand]Deployment
 [Expand]Task-Based Help
  Frequently Asked Questions (FAQ)
 [Expand]API Reference
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
This documentation page describes implementations made in our v17.2 release cycle. To learn about functionality shipping with v18.1, navigate to our updated help file experience at docs.devexpress.com. Learn More

Predefined State Transitions Created in Code

This topic describes how to create a predefined State Machine in code. A predefined State Machine cannot be changed by users. To learn how to define a state machine at runtime, refer to the User-Defined State Transitions Specified at Runtime topic instead.

Important

In certain scenarios, creating a custom Controller with the SingleChoiceAction Action or a set of SimpleAction Actions can be simpler and more straightforward than defining a coded State Machine. So, if you need to define a static state management process that should not be changed by users, consider this approach first instead of using the State Machine module.

See Also:

Add a Simple Action
Add a Parametrized Action
How to: Include an Action to a Detail View Layout

Note

To see this example in action, refer to the State Machine section of the Feature Center demo located in the %PUBLIC%\Documents\DevExpress Demos 18.1\Components\eXpressApp Framework\FeatureCenter folder by default, or refer to the Feature Center demo online.

The following code defines a simple Task business class, which can have different states such as not started, in progress, completed, etc.

To create a state machine for this class, perform the following steps.

  1. Declare a StateMachine<T> class descendant with the generic type parameter specifying the target business class. Override the Name property to provide a textual description for a state machine.

  2. Decide which business class property will be used as a state property. To function, a state machine must be able to distinguish between object states. This is why you need to specify a property whose values will represent different object states. This can be either an enumeration-typed property or a reference property. In this example, the Status property is a perfect candidate. Thus, it is used as a state property, and consequently, its values will be used as state markers. Note that different states must use different marker objects. To specify a state property, override the StatePropertyName property.

  3. Declare a set of allowed states and transitions between them. States are State class instances and transitions are Transition class instances. A state belongs to a state machine and has an associated caption and a marker. Each state has a collection of allowed transitions that specify possible target states. In this example, it should not be possible for a task to become completed until it is in progress, so the in progress state should not contain a completed transition.

    After you have defined states, transitions and appearance rules in a state machine constructor, add them to the machine's States collection. Override the StartState property to specify the initial state for newly created objects.

  4. A state machine can also optionally have Conditional Appearance rules associated with its states. These rules are represented by StateAppearance instances.

  5. Implement the IStateMachineProvider interface in the target business class. The interface's only member - GetStateMachines method - returns a list of all state machines available for the business class.

The State Machine module will display the ChangeStateAction Action in Task Views. The Action is provided by the StateMachineController.

Note

The StateMachineController is not designed to execute additional logic using its TransitionExecuting and TransitionExecuted events. Instead, place your custom code in the setter of the desired business class property.

You can optionally implement the IStateMachineUISettings interface and set its ExpandActionsInDetailView property to true.

In this instance, the target business class Detail Views will contain separate Simple Actions corresponding to available state transitions.

Is this topic helpful?​​​​​​​