MAUI Community Toolkit

Empowering your .NET MAUI development

Community Toolkit Services

The .NET MAUI Community Toolkit provides a collection of helpful services that abstract common cross-platform functionalities, making it easier and faster to build your .NET MAUI applications.

Featured Services

Clipboard Service

Easily copy and paste text to and from the device's clipboard. A fundamental service for many application interactions.

Learn More →

Preferences Service

Persist simple key-value pairs on the device. Ideal for storing user settings, session tokens, and other small data.

Learn More →

File System Service

Access and manage files and directories on the device's local storage. Provides a consistent API for file operations.

Learn More →

Geolocation Service

Retrieve the device's current location with ease. Supports various accuracy levels and background location updates.

Learn More →

Secure Storage Service

Store sensitive data securely on the device, leveraging platform-specific secure storage mechanisms.

Learn More →

Share Service

Enable users to share content from your app to other applications on the device. Supports text, URIs, and files.

Learn More →

Clipboard Service Details

The Clipboard Service allows you to interact with the system clipboard. You can set text to be copied and retrieve text that has been copied.

// In your ViewModel or Code-Behind var clipboardService = Application.Current.Handler.MauiContext.Services.GetService(); // Copy text await clipboardService.SetTextAsync("Hello, MAUI Community Toolkit!"); // Get text string clipboardContent = await clipboardService.GetTextAsync(); if (!string.IsNullOrEmpty(clipboardContent)) { // Do something with the clipboard content }

Preferences Service Details

The Preferences Service is your go-to for simple data persistence. It's perfect for storing settings like themes, user login states, or application preferences.

// In your ViewModel or Code-Behind var preferencesService = Application.Current.Handler.MauiContext.Services.GetService(); // Save a string preferencesService.Set("UserName", "JohnDoe"); // Get a string string userName = preferencesService.Get("UserName", "Guest"); // Provides a default value // Save a boolean preferencesService.Set("IsDarkModeEnabled", true); // Get a boolean bool isDarkMode = preferencesService.Get("IsDarkModeEnabled", false);

File System Service Details

Manage files and directories with the File System Service. It provides access to common locations like the application's documents directory.

// In your ViewModel or Code-Behind var fileSystemService = Application.Current.Handler.MauiContext.Services.GetService(); // Get the path to the app's documents directory string documentsPath = fileSystemService.AppDataDirectory; // Example: Save data to a file string filePath = Path.Combine(documentsPath, "mydata.txt"); await File.WriteAllTextAsync(filePath, "This is some data."); // Example: Read data from a file if (File.Exists(filePath)) { string fileContent = await File.ReadAllTextAsync(filePath); // Process fileContent }

Geolocation Service Details

Access the device's location information. This service abstracts the complexities of different platform APIs for obtaining location data.

// In your ViewModel or Code-Behind var geolocationService = Application.Current.Handler.MauiContext.Services.GetService(); try { var location = await geolocationService.GetLocationAsync(new GeolocationRequest(GeolocationAccuracy.High, TimeSpan.FromSeconds(10))); if (location != null) { double latitude = location.Latitude; double longitude = location.Longitude; // Use latitude and longitude } else { // Location not available } } catch (FeatureNotSupportedException fnsEx) { // Feature not supported on device } catch (PermissionException pEx) { // Location permission not granted } catch (Exception ex) { // Handle other exceptions }

Secure Storage Service Details

For sensitive information like API keys or user credentials, the Secure Storage Service provides a safe place to store them, leveraging platform-native security features.

// In your ViewModel or Code-Behind var secureStorageService = Application.Current.Handler.MauiContext.Services.GetService(); // Save sensitive data await secureStorageService.SetAsync("MyApiKey", "your_secret_api_key"); // Retrieve sensitive data string apiKey = await secureStorageService.GetAsync("MyApiKey"); if (!string.IsNullOrEmpty(apiKey)) { // Use the API key } // Remove sensitive data await secureStorageService.RemoveAsync("MyApiKey");

Share Service Details

Integrate seamless sharing capabilities into your application, allowing users to share text, URLs, or files with other apps.

// In your ViewModel or Code-Behind var shareService = Application.Current.Handler.MauiContext.Services.GetService(); // Share text await shareService.ShareAsync("Check out this amazing MAUI app!", "Share Title"); // Share a URI await shareService.ShareAsync(new ShareRequest { Title = "Share Website", Text = "Visit the MAUI Community Toolkit website.", Uri = "https://github.com/CommunityToolkit/Maui" }); // Share a file (example: sharing a generated report) // Assuming you have a file path to the report // string reportPath = Path.Combine(FileSystem.AppDataDirectory, "report.pdf"); // await shareService.ShareAsync(new ShareFileRequest // { // Title = "Share Report", // File = new ShareFile(reportPath) // });