Skip to content

Change events fire when the value is set from code #24

Closed

Description

@Shewart

Summary

Sidebar.SelectedValueChanged, Switch.Toggled and Select.SelectedIndexChanged fire when the value is set from code, exactly as when the user changes it. Handlers can't tell the two apart.

Steps to reproduce

mySwitch.Toggled += async (_, e) => await api.SetActive(user.Id, e.Value);
mySwitch.IsToggled = user.IsActive;   // fires Toggled → calls the API

Typical breakages:

  • Filling a table of switches from data calls the API once per row.
  • Syncing a sidebar with the router (a deep route /invoices/42 selecting the /invoices item) raises SelectedValueChanged, and an app that navigates on it jumps back to the section root.

Expected: these events fire only for user input (click, tap, keyboard), like Button.Clicked.

Suggested fix

Raise the events from the input handlers, not from the bindable properties' changed callbacks, or pass an IsUserInitiated flag in the event args. Apply it to MAUI and Avalonia, check other controls with the same pattern (Checkbox, RadioGroup, Slider, Tabs), and document the behaviour.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions