Advertisement

Forms, Input & Validation interview questions and answers

6 Forms, Input & Validation interview questions for .NET MAUI roles, each with a model answer, examples and likely follow-ups.

6 questions
Advertisement

6 questions

Q1 Beginner Save

How do you build a data entry form in MAUI?

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.
Likely follow-ups
  • How do you set the keyboard type? | Where does submit logic live?
Forms Data Binding & MVVM Input & Validation
Q2 Beginner Save

How do you use Picker and BindablePicker for selections?

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.
Likely follow-ups
  • What is ItemDisplayBinding? | SelectedItem vs SelectedIndex?
Forms Controls & Views Input & Validation
Q3 Intermediate Save

How do you implement real-time field validation as the user types?

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.
Likely follow-ups
  • Where do validation behaviors come from? | How do you show the error text?
Validation Behaviors Forms Input & Validation
Q4 Intermediate Save

What are Behaviors in MAUI and how do they help forms?

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.
Likely follow-ups
  • How do you make a behavior configurable? | Behavior vs Trigger?
Behaviors Validation Forms Input & Validation
Q5 Advanced Save

How do you implement INotifyDataErrorInfo for robust validation?

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.
Likely follow-ups
  • What does ObservableValidator add? | Can it do cross-field rules?
Validation MVVM Toolkit Forms Input & Validation
Q6 Advanced Save

How do you manage focus and keyboard behavior in forms?

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.
Likely follow-ups
  • How do you keep the focused field visible? | What does ReturnType do?
Forms Accessibility & UX Input & Validation