100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Handling User Input

How Entry, Editor, GestureRecognizers, and ViewModel-based validation work together to capture and validate user input in MAUI.

UI & LayoutsIntermediate9 min readJul 10, 2026
Analogies

Text Input Controls: Entry and Editor

Entry is MAUI's single-line text input control, exposing Keyboard (Keyboard.Numeric, Keyboard.Email, Keyboard.Telephone, etc.) to hint the platform's on-screen keyboard layout, IsPassword to mask characters, and ReturnType/ReturnCommand to customize and handle the keyboard's action button, while Editor is its multi-line counterpart used for longer free-form text like comments or notes, both exposing a two-way bindable Text property and TextChanged/Completed events.

🏏

Cricket analogy: Keyboard.Numeric hinting a numeric keypad is like an umpire's hand signal automatically cueing the scorer to expect a run-count entry rather than a wide or no-ball note.

Gestures and GestureRecognizers

Beyond typed text, MAUI captures input through GestureRecognizers attached to any View's GestureRecognizers collection: TapGestureRecognizer (with NumberOfTapsRequired for double-tap), PanGestureRecognizer for drag tracking, PinchGestureRecognizer for pinch-to-zoom, and SwipeGestureRecognizer with a Direction property (Left, Right, Up, Down), each exposing events or Command bindings so a plain Image or BoxView can become as interactive as a dedicated Button.

🏏

Cricket analogy: SwipeGestureRecognizer's Direction property is like a fielder diving in a specific direction, Left or Right, to intercept a shot — the gesture only fires when motion matches the declared direction, just as a dive only succeeds toward the ball's actual path.

xaml
<Image Source="card_back.png" WidthRequest="240" HeightRequest="140">
    <Image.GestureRecognizers>
        <TapGestureRecognizer NumberOfTapsRequired="2" Command="{Binding FlipCardCommand}" />
        <SwipeGestureRecognizer Direction="Left" Command="{Binding DismissCommand}" Threshold="80" />
    </Image.GestureRecognizers>
</Image>

<Entry Placeholder="Enter amount" Keyboard="Numeric"
       Text="{Binding Amount, Mode=TwoWay}"
       ReturnType="Done" ReturnCommand="{Binding SubmitCommand}" />

Validation and Input Constraints

Input validation in MAUI is typically handled in the ViewModel rather than the view — binding Entry.Text with Mode=TwoWay and validating on PropertyChanged, or using behaviors like the community toolkit's TextValidationBehavior with a regex Pattern, MinimumLength, and MaximumLength to enforce constraints and toggle visual feedback such as a red border color or an error Label, since MAUI has no built-in validation framework equivalent to WPF's IDataErrorInfo out of the box.

🏏

Cricket analogy: Validating Entry.Text in the ViewModel on PropertyChanged is like a third umpire continuously reviewing a batsman's foot position for a stumping the instant new frame data arrives, rather than waiting until the over ends.

Avoid running expensive or blocking validation logic directly inside a TextChanged event handler in code-behind — it fires on every keystroke and runs on the UI thread. Debounce validation (e.g., only validate after typing pauses) or keep checks lightweight, and prefer ViewModel-bound validation so the logic is testable outside the view.

  • Entry is single-line, Editor is multi-line, both expose two-way bindable Text
  • Keyboard property hints (Numeric, Email, Telephone) tailor the on-screen keyboard
  • GestureRecognizers (Tap, Pan, Pinch, Swipe) add interactivity to any View
  • SwipeGestureRecognizer's Direction property detects Left/Right/Up/Down swipes
  • MAUI has no built-in validation framework; use ViewModel logic or toolkit behaviors
  • TextValidationBehavior supports regex Pattern, MinimumLength, and MaximumLength
  • ReturnCommand handles the keyboard's action button declaratively

Practice what you learned

Was this page helpful?

Topics covered

#Programming#NETMAUIStudyNotes#HandlingUserInput#Handling#User#Input#Text#StudyNotes#SkillVeris#ExamPrep