PrismLibrary/Prism · error · ArgumentException

No matching event ' ' on attached type

Error message

No matching event '{EventName}' on attached type '{bindable.GetType().Name}'

What it means

Prism.Maui's EventToCommandBehavior resolves the event named by its EventName property on the attached control via GetRuntimeEvent; if reflection finds no such event, it throws ArgumentException. The behavior can only wire events that actually exist on the AssociatedObject type.

Solutions

  1. Correct the EventName to an event that exists on the attached control (check the exact casing).
  2. Verify the target control type actually declares the event (CollectionView vs ListView differences).
  3. Attach the behavior only via a targeted style/DataTemplate for the correct control type.
  4. If the event is platform-specific, guard with platform checks or use a different behavior.

Example fix

<!-- before -->
<prism:EventToCommandBehavior EventName="ItemSelected" Command="{Binding SelectedCommand}" />
<!-- after (CollectionView) -->
<prism:EventToCommandBehavior EventName="SelectionChanged" Command="{Binding SelectedCommand}" />
Defensive patterns

Strategy: validation

Validate before calling

var hasEvent = AssociatedObject?.GetType().GetRuntimeEvent(EventName) is not null;
if (!hasEvent) throw new ArgumentException($"Event '{EventName}' not found on control before attaching behavior");

Type guard

bool EventExists(object control, string name) => control.GetType().GetRuntimeEvent(name) is not null;

Try / catch

try { /* attach EventToCommandBehavior */ }
catch (ArgumentException ex) when (ex.Message.StartsWith("No matching event")) { /* fix EventName */ }

Prevention

When it happens

Trigger: Setting EventName to a name that doesn't exist on the attached control's type (typo, casing mismatch, event present only on a different platform/control), or attaching the behavior to a bindable whose runtime type differs from the one the event name was written for.

Common situations: Copying a behavior XAML snippet between controls (e.g. ItemTapped exists on ListView but not CollectionView); renaming events after a MAUI API change; attaching the behavior in a shared style applied to many control types.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15). Data as JSON: /api/errors/5a509790e6f0ca3d. Report an issue: GitHub.

Appendix: source

Thrown at src/Maui/Prism.Maui/Behaviors/EventToCommandBehavior.cs:161

        set => SetValue(EventArgsConverterParameterProperty, value);
    }

    /// <summary>
    /// Subscribes to the event <see cref="BindableObject"/> object
    /// </summary>
    /// <param name="bindable">Bindable object that is source of event to Attach</param>
    /// <exception cref="ArgumentException">Thrown if no matching event exists on 
    /// <see cref="BindableObject"/></exception>
    protected override void OnAttachedTo(BindableObject bindable)
    {
        base.OnAttachedTo(bindable);

        _eventInfo = AssociatedObject
            .GetType()
            .GetRuntimeEvent(EventName);
        if (_eventInfo == null)
        {
            throw new ArgumentException(
                $"No matching event '{EventName}' on attached type '{bindable.GetType().Name}'");
        }

        AddEventHandler(_eventInfo, AssociatedObject, OnEventRaised);
    }

    /// <summary>
    /// Unsubscribes from the event on <paramref name="bindable"/>
    /// </summary>
    /// <param name="bindable"><see cref="BindableObject"/> that is source of event</param>
    protected override void OnDetachingFrom(BindableObject bindable)
    {
        if (_handler != null)
        {
            _eventInfo.RemoveEventHandler(AssociatedObject, _handler);
        }
        _handler = null;
        _eventInfo = null;

View on GitHub (pinned to 358118cd64)