MahApps/MahApps.Metro · error · ArgumentException

The property 'SelectedItems' may only be set on ListBox, Mul

Error message

The property 'SelectedItems' may only be set on ListBox, MultiSelector or MultiSelectionComboBox elements.

What it means

Thrown by MultiSelectorHelper.OnSelectedItemsChanged when the dependency object the SelectedItems attached property is set on is not a ListBox, MultiSelector, or MultiSelectionComboBox. The helper binds an IList to the selection of multi-selection controls only; attaching it to any other element type is unsupported and rejected at the change callback.

Source

Thrown at src/MahApps.Metro/Controls/Helper/MultiSelectorHelper.cs:35

    /// Defines a helper class for SelectedItems binding on <see cref="ListBox"/>, <see cref="MultiSelector"/> or <see cref="MultiSelectionComboBox"/> controls.
    /// </summary>
    public static class MultiSelectorHelper
    {
        public static readonly DependencyProperty SelectedItemsProperty
            = DependencyProperty.RegisterAttached(
                "SelectedItems",
                typeof(IList),
                typeof(MultiSelectorHelper),
                new FrameworkPropertyMetadata(null, OnSelectedItemsChanged));

        /// <summary>
        /// Handles disposal and creation of old and new bindings
        /// </summary>
        private static void OnSelectedItemsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (d is not (ListBox or MultiSelector or MultiSelectionComboBox))
            {
                throw new ArgumentException("The property 'SelectedItems' may only be set on ListBox, MultiSelector or MultiSelectionComboBox elements.");
            }

            if (e.OldValue != e.NewValue)
            {
                GetSelectedItemBinding(d)?.UnBind();

                if (e.NewValue is IList newList)
                {
                    var multiSelectorBinding = new MultiSelectorBinding((Selector)d, newList);
                    SetSelectedItemBinding(d, multiSelectorBinding);
                    multiSelectorBinding.Bind();
                }
                else
                {
                    SetSelectedItemBinding(d, null);
                }
            }
        }

View on GitHub (pinned to 72099e310b)

Solutions

  1. Use a ListBox, MultiSelector-derived control (DataGrid, ListView), or MultiSelectionComboBox as the target.
  2. For single-selection controls (ComboBox), bind SelectedItem instead.
  3. If you need SelectedItems on a custom control, derive it from ListBox/MultiSelector or implement MultiSelectionComboBox semantics.
  4. Remove the MultiSelectorHelper.SelectedItems setter from incompatible elements.

Example fix

<!-- before -->
<ComboBox helper:MultiSelectorHelper.SelectedItems="{Binding Picks}" /> <!-- throws -->

<!-- after -->
<ListBox helper:MultiSelectorHelper.SelectedItems="{Binding Picks}" />
Defensive patterns

Strategy: type-guard

Validate before calling

if (d is not (ListBox or MultiSelector or MultiSelectionComboBox))
{
    throw new ArgumentException(
        $"{d.GetType()} is not supported by MultiSelectorHelper.SelectedItems.");
}

Type guard

static bool SupportsMultiSelectorSelectedItems(DependencyObject d)
    => d is ListBox or MultiSelector or MultiSelectionComboBox;

Prevention

When it happens

Trigger: Setting helper:MultiSelectorHelper.SelectedItems on a ComboBox, ItemsControl, TreeView, or any non-multi-selection Selector; applying the attached property to a custom control that is not derived from the supported base types.

Common situations: Trying to two-way bind SelectedItems on a plain ComboBox or ItemsControl where the framework has no SelectedItems property; copy-pasting the attached property from a ListBox onto an incompatible control.

Related errors


AI-assisted analysis of MahApps/MahApps.Metro@72099e310b (2026-08-13). Data as JSON: /api/errors/d8523ff46bd53279. Report an issue: GitHub.