.NET MAUI
Forms, Input & Validation
6 question(s)
How do you build a data entry form in MAUI?
Beginner
Compose Entry, Editor, Picker, DatePicker, TimePicker, Switch, and Stepper controls in a layout, bind each to view-model properties (two-way), and bind a submit Button to a command. Set keyboard types and placeholders to guide input. Keep validation and submission logic in the view model.
<Entry Placeholder="Name" Text="{Binding Name}" />
<DatePicker Date="{Binding BirthDate}" />
<Switch IsToggled="{Binding AcceptsTerms}" />
<Button Text="Submit" Command="{Binding SubmitCommand}" />
Real-world example
A registration form binds each field to the view model and disables Submit until required fields are filled.
Common follow-ups: How do you set the keyboard type? | Where does submit logic live?
Forms
Data Binding & MVVM
Forms
Input & Validation
How do you use Picker and BindablePicker for selections?
Beginner
Bind Picker.ItemsSource to a collection and SelectedItem (or SelectedIndex) to a view-model property; set ItemDisplayBinding to show a property of complex items. Picker presents a native selection UI on each platform.
<Picker Title="Country"
ItemsSource="{Binding Countries}"
ItemDisplayBinding="{Binding Name}"
SelectedItem="{Binding SelectedCountry}" />
Real-world example
A checkout form's country dropdown binds to a list of country objects and displays their names.
Common follow-ups: What is ItemDisplayBinding? | SelectedItem vs SelectedIndex?
Forms
Controls & Views
Forms
Input & Validation
How do you implement real-time field validation as the user types?
Intermediate
Bind TextChanged or use the view model's property setter to re-evaluate validation, expose an error message property, and show it with a bound label or DataTrigger. The CommunityToolkit's validation behaviors (e.g., TextValidationBehavior, EmailValidationBehavior) can apply visual states automatically.
<Entry Text="{Binding Email}">
<Entry.Behaviors>
<toolkit:EmailValidationBehavior
InvalidStyle="{StaticResource InvalidEntry}" />
</Entry.Behaviors>
</Entry>
Real-world example
An email field shows a red border immediately when the input isn't a valid address, using a validation behavior.
Common follow-ups: Where do validation behaviors come from? | How do you show the error text?
Validation
Behaviors
Forms
Input & Validation
What are Behaviors in MAUI and how do they help forms?
Intermediate
Behaviors attach reusable logic to a control without subclassing. Derive from Behavior<T>, override OnAttachedTo/OnDetachingFrom, and add event handlers or bindable properties. They're ideal for validation, input masking, or character limits applied declaratively across many controls.
public class MaxLengthBehavior : Behavior<Entry>
{
public int MaxLength { get; set; }
protected override void OnAttachedTo(Entry e) =>
e.TextChanged += (s, a) => { if (e.Text?.Length > MaxLength)
e.Text = e.Text[..MaxLength]; };
}
Real-world example
A phone-number field enforces a maximum length with a reusable behavior applied in XAML.
Common follow-ups: How do you make a behavior configurable? | Behavior vs Trigger?
Behaviors
Validation
Forms
Input & Validation
How do you implement INotifyDataErrorInfo for robust validation?
Advanced
Implement INotifyDataErrorInfo on the view model to expose per-property errors and raise ErrorsChanged. It supports async and cross-field validation and integrates with binding so the UI can reflect HasErrors and per-field messages. The MVVM Toolkit's ObservableValidator provides an attribute-driven implementation.
public partial class RegisterVm : ObservableValidator
{
[ObservableProperty]
[Required, EmailAddress]
string email;
// ValidateAllProperties() populates errors for binding
}
Real-world example
A form leverages DataAnnotations via ObservableValidator so [Required]/[EmailAddress] drive both validation and error display.
Common follow-ups: What does ObservableValidator add? | Can it do cross-field rules?
Validation
MVVM Toolkit
Forms
Input & Validation
How do you manage focus and keyboard behavior in forms?
Advanced
Call Focus()/Unfocus() to move focus programmatically (e.g., advance on Entry Completed), use ReturnType to set the keyboard's action key, and adjust for the on-screen keyboard with the platform's soft-keyboard handling (KeyboardScrollView patterns or Android windowSoftInputMode). Ensure the focused field stays visible.
<Entry ReturnType="Next" Completed="OnNameCompleted" />
void OnNameCompleted(object s, EventArgs e) => emailEntry.Focus();
Real-world example
Pressing Next on the name field jumps focus to the email field, streamlining form entry.
Common follow-ups: How do you keep the focused field visible? | What does ReturnType do?
Forms
Accessibility & UX
Forms
Input & Validation