About the Sample
This repository contains the source code for the MAUI Notes App sample. It's designed to showcase various features and best practices when developing cross-platform applications with .NET MAUI.
Key features demonstrated include:
- MVVM (Model-View-ViewModel) pattern
- Data persistence using SQLite
- UI design for multiple platforms (Windows, macOS, Android, iOS)
- Navigation between pages
- Handling user input and displaying data
- Using Dependency Injection
- Introduction to community toolkit features (optional)
Repository Structure
The project is organized into several key components:
- Platforms/: Contains platform-specific code (though largely abstracted in MAUI).
- Models/: Defines the data structures for notes.
- Views/: Contains the XAML files for the user interface.
- ViewModels/: Implements the MVVM pattern logic.
- Services/: Handles data access and other backend logic.
- App.xaml and App.xaml.cs: The entry point of the application.
- MauiProgram.cs: Configures the application services.
Getting Started
To build and run this sample, you will need:
- Visual Studio 2022 with the .NET Multi-platform App UI workload installed.
- .NET 6 SDK or later.
Steps:
- Clone this repository to your local machine.
- Open the solution file (e.g.,
Notes.sln) in Visual Studio. - Select your desired target platform and start debugging.
Key Code Snippet Example
Here's a glimpse into how data might be managed:
// In Notes.Services.NotesService.cs
public async Task<List<Note>> GetAllNotesAsync()
{
await _database.CreateTableAsync<Note>();
return await _database.Table<Note>().ToListAsync();
}
public async Task<int> SaveNoteAsync(Note note)
{
if (note.Id == 0)
{
return await _database.InsertAsync(note);
}
else
{
return await _database.UpdateAsync(note);
}
}