MaterialDesignInXAML/MaterialDesignInXamlToolkit · error · ArgumentNullException

comboBox

Error message

comboBox

What it means

ArgumentNullException(nameof(comboBox)) in ComboBoxHintProxy's constructor (HintProxyFabric.ComboBox.cs:12). The hint proxy wraps a ComboBox to drive the floating hint (SmartHint); a null ComboBox cannot be wrapped. Reachable when the internal HintProxyFabric (or a fork/test) constructs the proxy with null.

Source

Thrown at src/MaterialDesignThemes.Wpf/HintProxyFabric.ComboBox.cs:12

namespace MaterialDesignThemes.Wpf;

public static partial class HintProxyFabric
{
    private sealed class ComboBoxHintProxy : IHintProxy
    {
        private readonly ComboBox _comboBox;
        private readonly TextChangedEventHandler _comboBoxTextChangedEventHandler;

        public ComboBoxHintProxy(ComboBox comboBox)
        {
            if (comboBox is null) throw new ArgumentNullException(nameof(comboBox));

            _comboBox = comboBox;
            _comboBoxTextChangedEventHandler = ComboBoxTextChanged;
            _comboBox.AddHandler(TextBoxBase.TextChangedEvent, _comboBoxTextChangedEventHandler);
            _comboBox.SelectionChanged += ComboBoxSelectionChanged;
            _comboBox.Loaded += ComboBoxLoaded;
            _comboBox.IsVisibleChanged += ComboBoxIsVisibleChanged;
            _comboBox.IsKeyboardFocusWithinChanged += ComboBoxIsKeyboardFocusWithinChanged;
        }

        public bool IsLoaded => _comboBox.IsLoaded;

        public bool IsVisible => _comboBox.IsVisible;

        public bool IsEmpty() => string.IsNullOrEmpty(_comboBox.Text);

        public bool IsFocused() => _comboBox.IsEditable && _comboBox.IsKeyboardFocusWithin;

View on GitHub (pinned to 98edec3a0b)

Solutions

  1. Pass a valid ComboBox instance to the proxy; obtain it from the actual control being hinted.
  2. Do not instantiate ComboBoxHintProxy directly; let the framework's HintProxyFabric pick the correct proxy.
  3. In tests, use a real ComboBox rather than null; verify ControlTemplate/Style does not null-out the target.
Defensive patterns

Strategy: validation

Validate before calling

if (comboBox is null)
    throw new ArgumentNullException(nameof(comboBox));

// Let HintProxyFabric choose the adapter; do not construct ComboBoxHintProxy directly.

Type guard

static bool CanWrapComboBox(ComboBox? comboBox) => comboBox is not null;

Prevention

When it happens

Trigger: Constructing ComboBoxHintProxy with a null ComboBox reference; typically invoked internally from the hint-attached behavior when a ComboBox is involved. Direct public construction is internal-only.

Common situations: Test doubles/fakes; a custom Style/ControlTemplate that breaks the ComboBox reference path; library fork invoking the proxy with null; reflection-based instantiation.

Related errors


AI-assisted analysis of MaterialDesignInXAML/MaterialDesignInXamlToolkit@98edec3a0b (2026-08-13). Data as JSON: /api/errors/28311cbd07c6fa72. Report an issue: GitHub.