Triggers
Trigger types, registration, execution order and key triggers.
In this documentation
- Beep.Forms
- Architecture
- Authoring in the Object Navigator
- WinForms runtime
- WPF runtime
- End-to-end example
- Remote UI limitations
- Overview
- Context menus
- Blocks and items
- Triggers
- Lists of values
- Validation
- Master detail
- Navigation and queries
- Alerts, editors and timers
- Calling other forms
- Form menus
- Hosting in WinForms step by step
- Hosting in WPF step by step
- Saving and loading forms
- The IDE toolbar and dialogs
- Troubleshooting
Triggers are handlers that run at defined points. TriggerType lists the points. A TriggerDefinition binds a handler to one of them.
Trigger types
The TriggerType enum is grouped by numeric range.
| Group | Values |
|---|---|
| Form | 0 to 14 |
| Block | 20 to 44 |
| Record | 50 to 55 |
| Item | 70 to 81 |
| Navigation | 100 to 119 |
| Action | 120 to 138 |
| Function keys and other | 150 to 168 |
| Mouse | 170 to 178 |
| Timer | WhenTimerExpired (190) |
| Custom | Custom1 to Custom5 (200 to 204), WhenMenuItem (205), UserNamed (250) |
Each enum member carries a comment saying when it is meant to fire. Read the enum in the source for the full list of names.
Defining a trigger
manager.Triggers.RegisterTrigger(new TriggerDefinition(
TriggerType.WhenValidateItem, TriggerScope.Item)
{
TriggerId = "ord.qty.WhenValidateItem",
BlockName = "Ord", ItemName = "Qty", Handler = OnValidateQty,
});
TriggerScope is one of Form, Block, Record, Item, Global. The constructor fills TriggerName, Category and Timing. Other members include AsyncHandler, TimeoutMs, ContinueOnFailure, DependsOn, ChainMode, IsEnabled and Priority. Static helpers are CreateFormTrigger, CreateBlockTrigger, CreateItemTrigger and CreateAsyncBlockTrigger.
Manager methods
RegisterTrigger, RegisterFormTrigger, RegisterBlockTrigger, RegisterItemTrigger, RegisterGlobalTrigger and their async variants register handlers. UnregisterTrigger and ClearBlockTriggers remove them. FireFormTrigger, FireBlockTrigger and FireItemTrigger run them. SuspendTriggers and ResumeTriggers pause and resume firing. EnableTrigger and DisableTrigger switch one trigger.
Execution order
- Triggers run in descending
Priority.TriggerPriorityvalues are Lowest 0, Low 25, Normal 50, High 75, Highest 100 and System 255. - A form fire runs global and form triggers. A block fire runs global and block triggers. An item fire runs global, block and item triggers.
- The chain stops when
CancelorSkipRemainingTriggersis set on the context. A failing trigger withoutContinueOnFailuresetsSkipRemainingTriggers. - A result of
FormTriggerFailureor a cancel makes the overall resultFormTriggerFailure. A result ofCancelledmakes the overall resultCancelled.
TriggerResult members are Success, Failure, Exception, Cancelled, Skipped, Timeout and FormTriggerFailure. TriggerChainMode members are StopOnFailure, Continue and Rollback.
The context
A handler receives a TriggerContext. Useful members: Cancel, CancelMessage, Message, SkipRemainingTriggers, RaiseFormTriggerFailure(message), Parameters, GetParameter<T>, SetParameter, OldValue, NewValue, CurrentRecord, KeyCode, TimerName and FormsManager.
Triggers with known parameters
WhenTimerExpiredfires at form scope withParameters["TimerName"]andParameters["FireCount"].WhenMenuItemfires withParameters["MenuItemId"]andParameters["MenuItemCommand"].- When an item value changes on the current record and the item has a list of values,
WhenLOVValidationfires first, then the list membership check runs.
Key triggers
manager.RegisterKeyTrigger(KeyTriggerType, blockName, handler) registers a handler for a key. An empty or null block name means form scope. FireKeyTriggerAsync(KeyTriggerType, blockName) runs it. When the result is not Cancelled, the default action runs.
| Key trigger | Default action |
|---|---|
| Enter, Commit | CommitFormAsync |
| Exit | CloseFormAsync |
| ExecuteQuery | ExecuteQueryAsync |
| NextRecord, PreviousRecord | Record navigation |
| NextBlock, PreviousBlock | Block switch |
| Others | None |
Which engine operations raise which trigger
This page documents the firing points that were checked in the engine: the item, block and form chains above, key triggers, timers, menu items and list of value validation. Do not assume every member of TriggerType is raised by the built in operations. A trigger you register yourself can always be run with the Fire methods.