Book an appointment in .NET MAUI
A booking screen for iOS and Android from one C# project, with .NET MAUI and Lily: labelled choices, a line of guidance, and the bars a phone app has.
What you'll build
One screen of a booking app, on iOS and Android, with .NET MAUI: a top bar of labelled buttons, a large heading, a line of guidance, four choices (where, what type, with whom, and what time of day), and a tab bar. It is generic: a service anyone might book, with example places and people. About 30 minutes.
Before you start
You need the .NET 11 SDK with the MAUI workload (dotnet workload install maui),
and Xcode for iOS or the Android SDK for Android. LilyDesignSystem.Maui is not on
NuGet yet, so the app references it from a clone of the repository, beside the app:
git clone https://github.com/LilyDesignSystem/lily-design-system
dotnet new maui -n BookAppointment
cd BookAppointment
rm App.xaml App.xaml.cs AppShell.xaml AppShell.xaml.cs MainPage.xaml MainPage.xaml.cs
rm -r Resources/Styles Resources/Images/dotnet_bot.png The app is written in C#, so the template's XAML pages and styles go. Each code block below
is one whole file in BookAppointment; replace the file the template made where
the names match.
Step 1: The project
BookAppointment.csproj
<Project Sdk="Microsoft.NET.Sdk">
<!-- The book-an-appointment app: one page, drawn with Lily's MAUI controls. -->
<PropertyGroup>
<TargetFrameworks>net11.0-android;net11.0-ios</TargetFrameworks>
<OutputType>Exe</OutputType>
<RootNamespace>BookAppointment</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ApplicationTitle>Example Services</ApplicationTitle>
<ApplicationId>com.example.bookappointment</ApplicationId>
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">17.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">24.0</SupportedOSPlatformVersion>
</PropertyGroup>
<ItemGroup>
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#1F2A44" />
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#1F2A44" BaseSize="128,128" />
<MauiImage Include="Resources\Images\*.svg" BaseSize="24,24" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="11.0.10" />
</ItemGroup>
<ItemGroup>
<!-- Until LilyDesignSystem.Maui is on NuGet: a project reference into your clone of the monorepo. -->
<ProjectReference Include="../lily-design-system/lily-design-system-maui/src/LilyDesignSystem.Maui/LilyDesignSystem.Maui.csproj" />
</ItemGroup>
</Project> For white status-bar text on the navy band, add these two keys to the first <dict> in Platforms/iOS/Info.plist:
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
Step 2: Write the words
Words.cs
namespace BookAppointment;
/// <summary>Every word the app shows, in one place, so the app can be translated without touching a page.</summary>
public static class Words
{
public const string AppName = "Example Services";
public const string Home = "Home";
public const string Language = "Language";
public const string Help = "Help";
public const string Messages = "Messages";
public const string Title = "Book an appointment";
public const string Intro = "Choose a place and a type of appointment, then pick a time that suits you.";
public const string Location = "Location";
public const string Type = "Type of appointment";
public const string Person = "Staff member (optional)";
public const string TimeOfDay = "Filter by time of day";
public const string FindTimes = "Find times";
public const string Appointments = "Appointments";
public const string Orders = "Orders";
public const string Account = "Account";
public const string More = "More";
/// <summary>What a screen reader hears for the selected tab: MAUI has no selected trait for a button.</summary>
public static string Selected(string tab) => $"{tab}, selected";
} Step 3: Describe the booking
Booking.cs
namespace BookAppointment;
/// <summary>One choice in a list: the id the service knows it by, and the words the person sees.</summary>
public record Choice(string Id, string Label);
/// <summary>What the person has chosen, and the choices offered. The choices come from the service; these are examples.</summary>
public class Booking
{
public string Location { get; set; } = "main";
public string Type { get; set; } = "";
public string Person { get; set; } = "any";
public string TimeOfDay { get; set; } = "";
/// <summary>Times can be looked for once a type is chosen: the type decides how long the appointment is.</summary>
public bool CanFindTimes => Type.Length > 0;
public static readonly Choice[] Locations = [new("main", "Main office"), new("north", "North branch"), new("online", "Online")];
public static readonly Choice[] Types =
[new("", "Select type"), new("first", "First visit"), new("follow-up", "Follow-up"), new("advice", "Advice by phone")];
public static readonly Choice[] People = [new("any", "No preference"), new("sam", "Sam Okoro"), new("alex", "Alex Kim")];
public static readonly Choice[] TimesOfDay =
[new("", "Select an option"), new("morning", "Morning"), new("afternoon", "Afternoon"), new("evening", "Evening")];
} Step 4: Choose the colours and styles
Lily ships no brand, and its MAUI controls set no colour or size: an app styles them by style class, as the web themes style class names.
Brand.cs
namespace BookAppointment;
/// <summary>
/// The service's own colours. A brand colour colours a band or a line, never text on the page; the text on the band is white,
/// well above 4.5:1 on this navy (AGENTS/visual-identity.md). Lily ships no brand: these are yours.
/// </summary>
public static class Brand
{
public static readonly Color Band = Color.FromArgb("#1F2A44");
public static readonly Color OnBand = Colors.White;
public static readonly Color Line = Color.FromArgb("#C89B3C");
} AppStyles.cs
namespace BookAppointment;
/// <summary>
/// The app's styles for Lily's class hooks. Lily's controls set no colour, size or font; an app styles them by StyleClass, as
/// the web themes style the kebab-case classes.
/// </summary>
public static class AppStyles
{
public static ResourceDictionary Create()
{
var styles = new ResourceDictionary();
void Class<T>(string name, BindableProperty property, object value)
where T : BindableObject
{
var style = new Style(typeof(T)) { Class = name, ApplyToDerivedTypes = true };
style.Setters.Add(new Setter { Property = property, Value = value });
styles.Add(style);
}
Class<Label>("field-label", Label.FontSizeProperty, 17d);
Class<Label>("inset-text-text", Label.FontSizeProperty, 17d);
return styles;
}
} Step 5: Ask for a choice
Lily's Field draws the label and gives the control its spoken name. The box and
chevron are the app's; the platform's own field border is taken off in MauiProgram.cs.
ChoiceField.cs
using LilyDesignSystem.Maui;
namespace BookAppointment;
/// <summary>A labelled choice drawn as a box with a chevron, like a web select. Lily's Field gives the label and the spoken name.</summary>
public static class ChoiceField
{
public static Field Create(string label, Choice[] choices, string selected, Action<string> onSelect)
{
var picker = new Picker
{
ItemsSource = choices.Select(c => c.Label).ToList(),
SelectedIndex = Math.Max(0, Array.FindIndex(choices, c => c.Id == selected)),
FontSize = 17,
TextColor = Colors.Black,
};
picker.SelectedIndexChanged += (_, _) => onSelect(choices[picker.SelectedIndex].Id);
var chevron = new Image { Source = "chevron.png", WidthRequest = 22, HeightRequest = 22, VerticalOptions = LayoutOptions.Center };
AutomationProperties.SetIsInAccessibleTree(chevron, false);
var box = new Border
{
Stroke = Colors.Black,
StrokeThickness = 2,
BackgroundColor = Colors.White,
Padding = new Thickness(16, 4),
MaximumWidthRequest = 300,
HorizontalOptions = LayoutOptions.Start,
WidthRequest = 300,
HeightRequest = 52,
Content = new Grid
{
ColumnDefinitions = [new ColumnDefinition(GridLength.Star), new ColumnDefinition(GridLength.Auto)],
Children = { picker, chevron },
},
};
Grid.SetColumn(chevron, 1);
return new Field { Label = label, Control = box };
}
} Step 6: Draw the icons
MAUI turns each SVG in Resources/Images into an image for every platform, named …png.
Resources/Images/home.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="#FFFFFF" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M3 11 12 3l9 8"/><path d="M5 10v10h5v-6h4v6h5V10"/></svg> Resources/Images/language.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="#FFFFFF" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="3"/><path d="M8 17l4-10 4 10M9.5 13.5h5"/></svg> Resources/Images/help.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="#FFFFFF" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M9.5 9.5a2.5 2.5 0 1 1 3.5 2.3c-.6.3-1 .9-1 1.6v.6"/><path d="M12 17.5h.01"/></svg> Resources/Images/messages.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="#FFFFFF" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M4 5h16v11H9l-5 4z"/></svg> Resources/Images/logo.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="#FFFFFF"><circle cx="12" cy="12" r="3"/><circle cx="12" cy="5" r="3"/><circle cx="12" cy="19" r="3"/><circle cx="6" cy="8.5" r="3"/><circle cx="18" cy="8.5" r="3"/><circle cx="6" cy="15.5" r="3"/><circle cx="18" cy="15.5" r="3"/></svg> Resources/Images/calendar.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="#1F2A44" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="16" rx="2"/><path d="M3 10h18M8 3v4M16 3v4"/></svg> Resources/Images/bag.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="#18181B" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M6 8h12l-1 13H7z"/><path d="M9 8V6a3 3 0 0 1 6 0v2"/></svg> Resources/Images/account.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="#18181B" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><circle cx="12" cy="10" r="3"/><path d="M6.5 18.5a6.5 6.5 0 0 1 11 0"/></svg> Resources/Images/more.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="#18181B"><circle cx="6" cy="12" r="1.8"/><circle cx="12" cy="12" r="1.8"/><circle cx="18" cy="12" r="1.8"/></svg> Resources/Images/chevron.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="#18181B" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 9l6 6 6-6"/></svg> Step 7: Draw the page
Both bars are drawn here to match the service's design, and each paints its own edge of the
screen. MAUI has no selected trait for a button, so the selected tab says "selected" in its
spoken name, from Words.
BookAppointmentPage.cs
using LilyDesignSystem.Maui;
namespace BookAppointment;
/// <summary>
/// The app's one page: a top bar of labelled buttons, the form, and a tab bar. Both bars are drawn here so they match the
/// service's design.
/// </summary>
public class BookAppointmentPage : ContentPage
{
private readonly Booking booking = new();
public BookAppointmentPage()
{
// Each bar paints its own edge of the screen: the top bar under the status bar, the tab bar under the home indicator.
SafeAreaEdges = SafeAreaEdges.None;
BackgroundColor = Colors.White;
var find = new Button { Text = Words.FindTimes, IsEnabled = false, HorizontalOptions = LayoutOptions.Start };
void Changed() => find.IsEnabled = booking.CanFindTimes;
var title = new Label { Text = Words.Title, FontSize = 40, FontAttributes = FontAttributes.Bold, TextColor = Colors.Black };
SemanticProperties.SetHeadingLevel(title, SemanticHeadingLevel.Level1);
// Lily's InsetText is the words; the rail at its leading edge is the app's drawing.
var inset = new Grid { ColumnDefinitions = [new ColumnDefinition(4), new ColumnDefinition(GridLength.Star)], ColumnSpacing = 12 };
inset.Add(new BoxView { Color = Colors.Black }, 0);
inset.Add(new InsetText { Text = Words.Intro }, 1);
var form = new VerticalStackLayout
{
Spacing = 20,
Padding = new Thickness(20, 16),
Children =
{
title,
inset,
ChoiceField.Create(Words.Location, Booking.Locations, booking.Location, v => { booking.Location = v; Changed(); }),
ChoiceField.Create(Words.Type, Booking.Types, booking.Type, v => { booking.Type = v; Changed(); }),
ChoiceField.Create(Words.Person, Booking.People, booking.Person, v => { booking.Person = v; Changed(); }),
ChoiceField.Create(Words.TimeOfDay, Booking.TimesOfDay, booking.TimeOfDay, v => { booking.TimeOfDay = v; Changed(); }),
find,
},
};
var content = new Grid
{
SafeAreaEdges = SafeAreaEdges.None,
RowDefinitions = [new RowDefinition(GridLength.Auto), new RowDefinition(GridLength.Star), new RowDefinition(GridLength.Auto)],
};
content.Add(TopBar(), 0, 0);
content.Add(new ScrollView { Content = form, BackgroundColor = Color.FromArgb("#F8F8F8") }, 0, 1);
content.Add(TabBar(), 0, 2);
Content = content;
}
private static Button BarButton(string icon, string label, Color color) => new()
{
ImageSource = icon,
Text = label,
FontSize = 11,
TextColor = color,
BackgroundColor = Colors.Transparent,
Padding = new Thickness(4),
MinimumHeightRequest = 48,
MinimumWidthRequest = 52,
ContentLayout = new Button.ButtonContentLayout(Button.ButtonContentLayout.ImagePosition.Top, 2),
};
private static View TopBar()
{
var logo = new HorizontalStackLayout
{
Spacing = 6,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
Children =
{
new Image { Source = "logo.png", HeightRequest = 28, WidthRequest = 28 },
new Label { Text = Words.AppName, TextColor = Brand.OnBand, FontSize = 12, FontAttributes = FontAttributes.Bold, VerticalOptions = LayoutOptions.Center },
},
};
SemanticProperties.SetDescription(logo, Words.AppName);
SemanticProperties.SetHeadingLevel(logo, SemanticHeadingLevel.Level2);
var bar = new Grid
{
SafeAreaEdges = new SafeAreaEdges(SafeAreaRegions.None, SafeAreaRegions.All, SafeAreaRegions.None, SafeAreaRegions.None),
BackgroundColor = Brand.Band,
Padding = new Thickness(4, 0, 4, 8),
ColumnDefinitions =
[
new ColumnDefinition(GridLength.Auto), new ColumnDefinition(GridLength.Auto), new ColumnDefinition(GridLength.Star),
new ColumnDefinition(GridLength.Auto), new ColumnDefinition(GridLength.Auto),
],
};
bar.Add(BarButton("home.png", Words.Home, Brand.OnBand), 0);
bar.Add(BarButton("language.png", Words.Language, Brand.OnBand), 1);
bar.Add(logo, 2);
bar.Add(BarButton("help.png", Words.Help, Brand.OnBand), 3);
bar.Add(BarButton("messages.png", Words.Messages, Brand.OnBand), 4);
// The band reaches the top of the screen, under the status bar; the buttons stay below it.
return new ContentView { BackgroundColor = Brand.Band, SafeAreaEdges = SafeAreaEdges.None, Content = bar };
}
private static View TabBar()
{
(string Label, string Icon)[] tabs =
[(Words.Appointments, "calendar.png"), (Words.Orders, "bag.png"), (Words.Account, "account.png"), (Words.More, "more.png")];
var bar = new Grid { BackgroundColor = Colors.White, Padding = new Thickness(0, 6, 0, 0) };
for (var i = 0; i < tabs.Length; i++)
{
bar.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Star));
var button = BarButton(tabs[i].Icon, tabs[i].Label, i == 0 ? Brand.Band : Colors.Black);
if (i == 0)
{
button.FontAttributes = FontAttributes.Bold;
SemanticProperties.SetDescription(button, Words.Selected(tabs[i].Label));
}
bar.Add(button, i);
}
return new VerticalStackLayout
{
SafeAreaEdges = new SafeAreaEdges(SafeAreaRegions.None, SafeAreaRegions.None, SafeAreaRegions.None, SafeAreaRegions.All),
Children = { new BoxView { Color = Brand.Line, HeightRequest = 2 }, bar },
BackgroundColor = Colors.White,
};
}
} Step 8: Start the app
MauiProgram.cs
using LilyDesignSystem.Maui.Themes;
namespace BookAppointment;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder.UseMauiApp<App>();
// The box round each choice is the app's (ChoiceField), so the platform's own field border is taken off.
Microsoft.Maui.Handlers.PickerHandler.Mapper.AppendToMapping("NoBorder", (handler, _) =>
{
#if IOS
handler.PlatformView.BorderStyle = UIKit.UITextBorderStyle.None;
#elif ANDROID
handler.PlatformView.Background = null;
#endif
});
return builder.Build();
}
}
public class App : Application
{
public App()
{
// The light theme's tokens, for {DynamicResource lily-color-…}, and the app's styles for Lily's class hooks.
LilyTheme.Apply(Resources, LilyTokens.Light);
Resources.MergedDictionaries.Add(AppStyles.Create());
}
protected override Window CreateWindow(IActivationState? activationState) =>
new(new BookAppointmentPage()) { Title = Words.AppName };
} Run it with dotnet build -t:Run -f net11.0-ios, or -f net11.0-android with an emulator running.
Check your work: turn on VoiceOver or TalkBack and move through the screen: each choice says its label, then its value, and the Appointments tab says it is selected. "Find times" is dimmed until you choose a type.
What this does not do yet
- The buttons in the bars and "Find times" do nothing: the screen is the lesson, not the booking.
- The choices are fixed examples. A real app asks its service for them, in the person's language.
- It has one language. The words are in one place, so adding another touches no view.
Next steps
- Swift version: the same screen on iOS with SwiftUI.
- Kotlin version: the same screen on Android with Jetpack Compose.