MaterialDesignInXAML/MaterialDesignInXamlToolkit · error · ArgumentNullException
passwordBox
Error message
passwordBox
What it means
ArgumentNullException(nameof(passwordBox)) in PasswordBoxHintProxy's constructor (HintProxyFabric.PasswordBox.cs:26). The proxy adapts a PasswordBox for the floating SmartHint; wrapping null is illegal. Thrown when the proxy is constructed with a null PasswordBox (internal/fork/test code).
Source
Thrown at src/MaterialDesignThemes.Wpf/HintProxyFabric.PasswordBox.cs:26
public bool IsEmpty() => string.IsNullOrEmpty(_passwordBox.Password);
public object Content => _passwordBox.Password;
public bool IsLoaded => _passwordBox.IsLoaded;
public bool IsVisible => _passwordBox.IsVisible;
public bool IsFocused() => _passwordBox.IsKeyboardFocusWithin;
public event EventHandler? ContentChanged;
public event EventHandler? IsVisibleChanged;
public event EventHandler? Loaded;
public event EventHandler? FocusedChanged;
public PasswordBoxHintProxy(PasswordBox passwordBox)
{
if (passwordBox is null) throw new ArgumentNullException(nameof(passwordBox));
_passwordBox = passwordBox;
_passwordBox.PasswordChanged += PasswordBoxPasswordChanged;
_passwordBox.Loaded += PasswordBoxLoaded;
_passwordBox.IsVisibleChanged += PasswordBoxIsVisibleChanged;
_passwordBox.IsKeyboardFocusWithinChanged += PasswordBoxIsKeyboardFocusedChanged;
}
private void PasswordBoxIsKeyboardFocusedChanged(object sender, DependencyPropertyChangedEventArgs e)
=> FocusedChanged?.Invoke(this, EventArgs.Empty);
private void PasswordBoxIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
=> IsVisibleChanged?.Invoke(this, EventArgs.Empty);
private void PasswordBoxLoaded(object sender, RoutedEventArgs e)
=> Loaded?.Invoke(this, EventArgs.Empty);
private void PasswordBoxPasswordChanged(object sender, RoutedEventArgs e)View on GitHub (pinned to 98edec3a0b)
Solutions
- Pass a valid PasswordBox instance; resolve it from the actual control receiving the hint.
- Do not construct PasswordBoxHintProxy directly; rely on HintProxyFabric to select the adapter.
- In tests, use a real PasswordBox; confirm Style/Template does not produce a null target.
Defensive patterns
Strategy: validation
Validate before calling
if (passwordBox is null)
throw new ArgumentNullException(nameof(passwordBox));
// Let HintProxyFabric choose the adapter; do not construct PasswordBoxHintProxy directly. Type guard
static bool CanWrapPasswordBox(PasswordBox? passwordBox) => passwordBox is not null;
Prevention
- Do not instantiate PasswordBoxHintProxy directly; rely on HintProxyFabric.
- Confirm PasswordBox styles/templates do not produce a null target.
- In tests, use a real PasswordBox rather than null.
When it happens
Trigger: Constructing PasswordBoxHintProxy with a null PasswordBox; usually reached via the internal HintProxyFabric attached behavior. The public API does not construct the proxy directly.
Common situations: Test doubles/fakes; a broken Style/ControlTemplate that resolves the PasswordBox to null; reflection; library fork.
Related errors
AI-assisted analysis of MaterialDesignInXAML/MaterialDesignInXamlToolkit@98edec3a0b (2026-08-13).
Data as JSON: /api/errors/7240d9a401c524d2.
Report an issue: GitHub.