/// <summary> /// Gets the submenu from the collection with the specified text, optionally creating one if not found. /// </summary> /// <returns>The submenu instance if found, or a new submenu instance added at the specified order.</returns> /// <param name="submenuText">Text of the submenu to find or add.</param> /// <param name="order">Order of the submenu item to add. Not used if there is already a submenu with the specified text.</param> /// <param name="plaintextMatch">If set to <c>true</c>, matches excluding any mnemonic symbol idenfifiers.</param> /// <param name="create">If set to <c>true</c>, creates the menu if it doesn't exist in the collection, otherwise <c>false</c>.</param> public ButtonMenuItem GetSubmenu(string submenuText, int order = 0, bool plaintextMatch = true, bool create = true) { if (string.IsNullOrEmpty(submenuText)) { throw new ArgumentOutOfRangeException(nameof(submenuText), "submenuText must be a non null, non-empty value"); } // replace accelerators if plaintextMatch is true string convert(string s) => plaintextMatch?s?.Replace("&", "") : s; var matchText = convert(submenuText); bool match(MenuItem r) => convert(r.Text) == matchText; var submenu = this.OfType <ButtonMenuItem>().FirstOrDefault(match); if (submenu == null && create) { submenu = new SubMenuItem { Text = submenuText, Order = order, Trim = true }; Add(submenu); } return(submenu); }
/// <summary> /// Raises the <see cref="Closing"/> event. /// </summary> public void OnClosing(SubMenuItem widget, EventArgs e) { using (widget.Platform.Context) widget.OnClosing(e); }