Skip to content
Tutorials Center
My learning

Topics

Lesson 42 of 42 ยท Projects and Practice

Practice: Exercises and Interview Questions

Practice .NET MAUI with exercises (with runnable C# solutions for the logic parts) and 25 interview questions with concise answers on XAML, binding, MVVM, navigation, platform code and publishing.

You learn an app framework by building with it, and you prove it by explaining it. This lesson gives you exercises to build, with runnable C# solutions for the logic parts, and a long list of interview questions with short, accurate answers. Try each exercise before you read the solution.

MAUI itself cannot run on this site. Exercises are written so the rules live in plain C# (which runs here and in a unit test), and only the display needs a device.

Exercises

A search box should call the server 300 ms after the user stops typing, not on every key. Write a class Debouncer with Task Run(Func<Task> action) that cancels any previous pending call.

C# Solution: debouncer

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

In an app you would call debouncer.Run(() => SearchAsync(text)) from the TextChanged handler.

2. A tip calculator

Build a page with a bill Entry, a tip Slider (0 to 30%), a Stepper for the number of people and labels for tip, total and amount per person. Put the math in a class so you can test it, round up to the next cent for each person's share so the group never underpays.

C# Solution: tip math

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

3. Responsive column count

For a photo grid, choose the number of columns from the window width: 2 columns under 500, 3 under 800, 4 under 1100, otherwise as many 280-unit columns as fit (at least 4, at most 8). Use it in SizeChanged.

C# Solution: column picker

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

4. More to build (no solution given)

  1. Counter with persistence. A button counter that survives restarts with Preferences.
  2. Login form. Email and password entries, a validation message that updates as you type, a disabled Sign in button until valid.
  3. Settings page with a theme picker (System, Light, Dark), saved and applied at startup.
  4. Shell app with three tabs, a detail route with query parameters and a back button that asks "Discard changes?".
  5. Offline-first to-do list that queues changes while offline and syncs when connectivity returns.
  6. Camera capture that saves a photo to the app folder and shows a thumbnail list.
  7. Unit tests for exercises 1 to 3 and for every view model you wrote.

Interview questions

Answers are short on purpose; interviewers like you to expand with an example.

Basics

  1. What is .NET MAUI? A cross-platform framework for building native apps for Android, iOS, macOS (Mac Catalyst) and Windows from one C# and XAML codebase, on .NET.
  2. How does it differ from Xamarin.Forms? MAUI is its successor: single-project structure, .NET 6+ instead of Mono-based Xamarin, handlers instead of renderers, and built-in dependency injection and hosting.
  3. What is a handler? The object that creates the native control for a virtual view (Entry to EditText and so on) and maps properties to it. Renderers were the older, heavier mechanism.
  4. What is the single-project structure? One project with a Platforms folder for platform code and shared Resources (images, fonts, icons) that the build converts per platform.
  5. What does MauiProgram.CreateMauiApp do? Builds the host: registers the app, fonts, services, handlers and logging, then returns the MauiApp.

XAML and layout

  1. StackLayout vs Grid? Stacks arrange children in a line; a grid uses rows and columns. Prefer Grid for complex screens and avoid deep nesting for performance.
  2. What do Auto, * and absolute sizes mean in a Grid? Auto fits content, * shares the remaining space proportionally, a number is a fixed size.
  3. What is HorizontalOptions? The alignment (and whether it expands) of a view inside its parent's slot, as opposed to HorizontalTextAlignment, which aligns text inside the view.
  4. StaticResource vs DynamicResource? Static resolves once at load; dynamic follows later changes to the resource, needed for theme switching.
  5. What is x:DataType for? It enables compiled bindings, catching errors at build time and improving speed.

Binding and MVVM

  1. What is INotifyPropertyChanged? The interface a view model implements to tell bindings a property changed.
  2. Binding modes? OneWay, TwoWay, OneTime and OneWayToSource; Entry.Text defaults to TwoWay, Label.Text to OneWay.
  3. Why ObservableCollection<T>? It raises collection change events, so lists update when items are added or removed.
  4. What does the MVVM Community Toolkit add? Source generators for properties ([ObservableProperty]), commands ([RelayCommand]), messaging and validation, removing boilerplate.
  5. How do you handle a command's enabled state? Implement CanExecute and raise CanExecuteChanged when its inputs change (the toolkit does it with NotifyCanExecuteChangedFor).
  1. Shell vs NavigationPage? Shell provides a URI-based routing model plus flyout and tabs; NavigationPage is a plain stack.
  2. How do you pass data between pages? Query parameters ([QueryProperty]), a dictionary parameter in GoToAsync, or shared services and messaging.
  3. How do you run platform-specific code? #if ANDROID conditional compilation, platform folders with partial classes, DeviceInfo.Platform checks, or interfaces registered per platform.
  4. How do permissions work? Declare them in the platform manifest and request at run time with Permissions.RequestAsync<T>(), handling denial gracefully.
  5. How do you store secrets? SecureStorage (Keychain, Android Keystore, Windows DPAPI). Preferences is not encrypted.

Quality and delivery

  1. How do you unit test a view model? Keep it in a plain library, inject services as interfaces and use fakes; assert on state and commands.
  2. What is Hot Reload? Applying XAML and C# edits to a running app without rebuilding.
  3. How do you improve startup time? Light CreateMauiApp, lazy services, a quick first page, trimming and AOT in Release, compiled bindings.
  4. How do you update the UI from a background thread? MainThread.BeginInvokeOnMainThread or MainThread.InvokeOnMainThreadAsync.
  5. How do you ship to the stores? Unique ApplicationId, an increasing build number, signing (keystore or certificates), release build (.aab, .ipa, MSIX) and a store listing; test on a real device first.

Self test: spot the bug

Each snippet has a flaw. Try to name it before the quiz.

C#
// A
public ObservableCollection<Item> Items { get; set; }
public void Reload() => Items = LoadItems();   // no PropertyChanged

// B
var client = new HttpClient();                   // created for every request in a loop

// C
public async void OnSaveClicked(object? s, EventArgs e) => await SaveAsync();   // no try/catch

// D
Preferences.Default.Set("token", jwt);          // storing a secret

A: replacing the collection needs OnPropertyChanged (or mutate the same instance). B: socket exhaustion; reuse one client via IHttpClientFactory. C: exceptions crash the app; handle them. D: use SecureStorage.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does a debouncer do for a search box?

    It delays the action and cancels the previous pending call, so only the last text is searched.
  2. 2. Where should the tip calculation live so it can be tested?

    Pure logic in a normal class is tested without a device.
  3. 3. Which storage is appropriate for an authentication token?

    SecureStorage uses the platform's secure stores; Preferences and plain files are not encrypted.
  4. 4. What replaced renderers in MAUI?

    Handlers map virtual views to native controls and are lighter and easier to customize than renderers.

Summary

  • Put rules (debouncing, calculations, layout decisions) in plain C# so they are testable.
  • Build the extra exercises; each exercises a different part of the framework.
  • Be ready to explain handlers, bindings, MVVM, navigation, platform code, performance and publishing with a concrete example.

You have reached the end of this slice. Return to the track page to continue with any chapter.

Next: Back to the .NET MAUI course