MahApps/MahApps.Metro · warning · NotSupportedException
Unknown SelectionMode
Error message
Unknown SelectionMode
What it means
Thrown by the MahApps clear-text command when a MultiSelectionComboBox.SelectionMode value is not Single, Multiple, or Extended. The switch exhausts the standard System.Windows.Controls.SelectionMode enum; the default branch is a defensive guard against an unexpected/extended enum value. In normal usage this is unreachable because SelectionMode only has those three members.
Source
Thrown at src/MahApps.Metro/Controls/Helper/MahAppsCommands.cs:122
if (comboBox is MultiSelectionComboBox multiSelectionComboBox)
{
if (multiSelectionComboBox.HasCustomText)
{
multiSelectionComboBox.ResetEditableText(true);
}
else
{
switch (multiSelectionComboBox.SelectionMode)
{
case SelectionMode.Single:
multiSelectionComboBox.SetCurrentValue(MultiSelectionComboBox.SelectedItemProperty, null);
break;
case SelectionMode.Multiple:
case SelectionMode.Extended:
multiSelectionComboBox.SelectedItems?.Clear();
break;
default:
throw new NotSupportedException("Unknown SelectionMode");
}
multiSelectionComboBox.ResetEditableText(true);
}
comboBox.GetBindingExpression(ComboBox.TextProperty)?.UpdateSource();
comboBox.GetBindingExpression(MultiSelectionComboBox.SelectedItemProperty)?.UpdateSource();
comboBox.GetBindingExpression(MultiSelectionComboBox.SelectedItemsProperty)?.UpdateSource();
}
else
{
if (comboBox.IsEditable)
{
comboBox.SetCurrentValue(ComboBox.TextProperty, string.Empty);
comboBox.GetBindingExpression(ComboBox.TextProperty)?.UpdateSource();
}
comboBox.SetCurrentValue(Selector.SelectedItemProperty, null);View on GitHub (pinned to 72099e310b)
Solutions
- Use only the standard SelectionMode values (Single, Multiple, Extended) on MultiSelectionComboBox.
- If extending SelectionMode, patch this switch to handle the new case.
- Report the unexpected value to MahApps if a stock enum legitimately produces it.
- Avoid casting arbitrary integers into SelectionMode.
Defensive patterns
Strategy: validation
Validate before calling
// SelectionMode is a closed enum (Single, Multiple, Extended). Validate before relying on it.
if (multiSelectionComboBox.SelectionMode is not (SelectionMode.Single or SelectionMode.Multiple or SelectionMode.Extended))
{
throw new ArgumentOutOfRangeException(nameof(multiSelectionComboBox.SelectionMode));
} Type guard
static bool IsKnownMode(SelectionMode m)
=> m == SelectionMode.Single || m == SelectionMode.Multiple || m == SelectionMode.Extended; Try / catch
try { /* invoke clear command */ }
catch (NotSupportedException ex) when (ex.Message == "Unknown SelectionMode")
{
// A future/invalid SelectionMode value; reset to a known mode.
multiSelectionComboBox.SelectionMode = SelectionMode.Single;
} Prevention
- Only set SelectionMode to Single, Multiple, or Extended.
- Never cast arbitrary integers into SelectionMode.
- If extending the enum, patch the MahApps switch to cover the new member.
When it happens
Trigger: Calling the MahApps 'Clear' textbox command (e.g. clear-text button) on a MultiSelectionComboBox whose SelectionMode was set to a non-standard enum value via reflection or a future framework enum extension; a custom derivative overriding SelectionMode semantics.
Common situations: Effectively unreachable with the current WPF SelectionMode enum; would surface if a fork adds a new SelectionMode member without updating this switch, or if an invalid integer is cast into SelectionMode.
Related errors
- Type must be for an Enum.
- The EnumType must be specified.
- The provided dialog is already visible in the specified wind
- The provided dialog is not visible in the specified window.
- Dialog isn't visible to close
AI-assisted analysis of MahApps/MahApps.Metro@72099e310b (2026-08-13).
Data as JSON: /api/errors/a5a85de33bb5638e.
Report an issue: GitHub.