Calling other forms
CALL_FORM modes, the form registry, factories and messaging.
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
Modes
FormCallMode is Modal, Modeless or Replace. Manager methods: CallFormAsync(name, parameters, mode, ct), OpenFormModelessAsync, NewFormAsync, ReturnToCallerAsync(returnData), GetFormParameter(name), GetCallStack.
Shared state and messaging: SetGlobalVariable, GetGlobalVariable, SendParameterToForm, PostMessage(targetForm, messageType, payload), BroadcastMessage, SubscribeToMessage and UnsubscribeFromMessage.
Register the target form
A form can only be called when it is in the engine form registry. FormRegistry is on the concrete DMEEditor, not on IDMEEditor.
((TheTechIdea.Beep.DMEEditor)editor).FormRegistry.RegisterForm("OrderDetail", manager);
manager.CurrentFormName = "OrderEntry";
When the target is not registered, CallFormAsync returns false and the WinForms host shows an error saying the form is not registered in the engine's form registry, or that its WHEN-NEW-FORM-INSTANCE trigger declined it.
Form factory
The host needs a FormFactory that creates the window.
- WinForms: an
IWinFormFormsFactorywithShowModalAsync,ShowModelessAsync,ReplaceCurrentAsync(each takes the form name, a read only dictionary of parameters and a cancellation token) andReturnToCallerAsync(returnData, ct). - WPF: a function from the form name and an optional parameter dictionary to a
Window. The host shows and closes the window.
_masterHost.FormFactory = (_, parameters) => new OrderDetailWindow(manager, parameters);
Without a factory the host throws "A WinForms form factory must be assigned before opening another form." or the WPF equivalent.
Example flow
The end to end example calls CallFormAsync("OrderDetail", parameters, FormCallMode.Modal) with the parameters OrderId and Qty. The called form's host calls ReturnToCallerAsync() when it is done.