/// <summary> /// Apply button behavior by UX conventions, ie the left most button is used to confirm and the right most button to cancel. /// </summary> /// <param name="choices"></param> /// <returns></returns> internal static ButtonContext <TChoice>[] ConvertToButtons <TChoice>(params TChoice[] choices) { var result = new ButtonContext <TChoice> [choices.Length]; if (choices == null || !choices.Any()) { throw new ArgumentException($"{nameof(choices)} is null or empty"); } else if (choices.Length == 1) { result[0] = new ButtonContext <TChoice>(choices.Single(), true, false); } else { for (int i = 0; i < choices.Length; i++) { var choice = choices[i]; if (i == 0) { result[i] = new ButtonContext <TChoice>(choice, true, false); } else if (i == choices.Length) { result[i] = new ButtonContext <TChoice>(choice, false, true); } else { result[i] = new ButtonContext <TChoice>(choice, false, false); } } } return(result); }
protected virtual Unit OnButtonClicked(ButtonContext <TChoice> button) { _buttonHandler?.Invoke(button); DialogResult = button.IsDefault; return(Unit.Default); }