Files
Terminal.Gui/Terminal.Gui.Analyzers/TGUI001.md
Thomas Nind 3a645191db Fixes #4170 - Added analyzer that flags when user does not have Handled=true (#4182)
* Added analyzer

* WIP - Trying to create tests, failing with bad dependencies

* Working test woo

* Tidy up

* Tidy up

* Fix integration tests failing on command line

* Use 4.11 compiler

* Fix expecting 'e' as param name

* Make analyzer come as part of Terminal.Gui

* Add docs

* Fix warnings
2025-07-07 09:14:43 -06:00

779 B

TGUI001: Describe what your rule checks

Category: Reliability
Severity: Warning
Enabled by default: Yes

Cause

When registering an event handler for Accepting, you should set Handled to true, this prevents other subsequent Views from responding to the same input event.

Reason for rule

If you do not do this then you may see unpredictable behaviour such as clicking a Button resulting in another IsDefault button in the View also firing.

See:

How to fix violations

Set Handled to true in your event handler

Examples

var b = new Button();
b.Accepting += (s, e) =>
{
    // Do something

+    e.Handled = true;
};