Property AssignHotKeys
AssignHotKeys
Gets or sets whether this view assigns hotkeys to its subviews, and whether it accepts an automatically assigned hotkey from its superview.
public bool? AssignHotKeys { get; set; }
Property Value
- bool?
Remarks
The default is null. null does not assign hotkeys to subviews. A superview with this property set to true may still assign a hotkey to this view. Leave the property null on a subview that should receive an automatic hotkey.
Set the property to true to assign hotkeys to subviews, preferring an available programmatically set or view-derived HotKey before title-based hotkeys. UsedHotKeys keeps those keys unique. Set UsedHotKeys before adding subviews when other views already use keys that must not be chosen.
Set the property to false to decline automatic assignment. A superview does not insert a HotKeySpecifier into Title and does not choose a character for this view. A programmatically set HotKey and a specifier already written in the title are kept. false also does not assign hotkeys to this view's subviews. Hotkeys already assigned to those subviews are left in place.
When true, hotkeys are assigned to subviews when they are added via Add(View?). A subview whose AssignHotKeys is false is skipped. The assignment algorithm:
- Checks if the subview already has a programmatically set HotKey; if so and the key is not already used, reserves and preserves that hotkey; if already used, assigns a distinct title-based hotkey when possible
- If there is no programmatic hotkey, checks for a view-specific derived hotkey and reserves it before considering the title
- If there is no explicit or derived hotkey, checks if the subview's Title contains a hotkey specifier (e.g., Strings.menuFile) and preserves it if the key is not already used
- If neither a derived hotkey nor a usable title specifier is found, assigns a new hotkey from the first available character in the title. User-written title specifiers are preserved if their key is already reserved; the view then uses a distinct available title character
- Skips characters that are already in UsedHotKeys, as well as spaces and control characters, when determining whether a hotkey is usable or when assigning a new one
If enabled on the superview, changing a subview's Title releases the previous hotkey reservation owned by that subview from UsedHotKeys and reassigns from the new title. A subview with AssignHotKeys set to false keeps its programmatic hotkey or its existing title specifier instead of receiving a new one. A programmatically set HotKey takes precedence over a title specifier when its key is available. If another view has already reserved it, the first reservation is kept and this view uses an available title character instead. If no alternate character is available, the explicit hotkey remains set but is not reserved. Otherwise, a title specifier is preferred, followed by the first available character. Reassigning hotkeys, including calling AssignHotKeysToSubViews() repeatedly, preserves a programmatic hotkey whenever its key remains available.
When a user-written title specifier conflicts, the first specifier is repositioned before the distinct character assigned to the view. Additional specifiers remain in the title. Repositioning uses the normal TitleChanging and TitleChanged workflow, so handlers can rewrite or cancel it.
Views that derive a hotkey from content, such as Markdown, use that content instead of Title. If such a view has no content hotkey, title-based assignment is not used.
Hotkey assignment is not restricted by the subview's CanFocus value.
Call AssignHotKeysToSubViews() to manually trigger hotkey assignment for all subviews.