The static ModalRoot and PopupRoot properties provide an InteractiveGue which serve as the root for any element which should appear on top of other elements. These properties have the following characteristics:
Automatically created by FormsUtilities.InitializeDefaults
Automatically resized to fit the entire screen, including if the GraphicalUiElement.CanvasHeight
and GraphicalUiElement.CanvasWidth
change.
Both Remains on top of all other elements for its given layer. ModalRoot appears on top of PopupRoot.
These properties can be used in custom code to place elements (such as custom popup and toast elements) above all other elements.
ModalRoot and PopupRoot are used internally by Gum Forms. For example PopupRoot is used to display the ListBox which appears when expanding a ComboBox.
Popups which are placed on the ModalRoot element are considered modal - they block the input of all other controls. This is useful if you would like to create a popup which must be clicked before any other elements receive input. If multiple elements are added to ModalRoot, only the last item (and its children) receive input events. This allows one popup to show another popup.
By contrast, elements added to the PopupRoot are not modal - other elements can receive input.
The ComboBox control normally places its expanded form ListBox on PopupRoot; however if the ComboBox is on a ModalRoot then its ListBox is also added to ModalRoot.
The following code can be used to display a popup to either ModalRoot or PopupRoot depending on the isModal
value.
The IsFocused property gets or sets whether a component has focus. For example a TextBox will have its IsFocused set to true if the caret is visible and if it is taking input from the keyboard.
IsFocused can be directly assigned to give focus to an object. For example the following code gives a TextBoxInstance focus:
If you are setting focus on a TextBox in response to a click event, you may need to also clear the Cursor's input. For example, the following would set focus on TextBoxInstance when ButtonInstance is clicked: