MauiPersianToolkit is a comprehensive library for .NET MAUI that provides a variety of Persian language UI controls and components with full support for multiple calendar systems. This library is designed to help developers create modern, cross-platform applications with support for Persian language and right-to-left (RTL) layouts.
You can install the MauiPersianToolkit package via NuGet Package Manager or .NET CLI:
Install-Package MauiPersianToolkit
dotnet add package MauiPersianToolkit
Add the Persian Toolkit to your MauiApp in MauiProgram.cs:
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
fonts.AddFont("IranianSans.ttf", "IranianSans");
})
.UseMauiCommunityToolkit()
.UsePersianUIControls(); // Add this line
return builder.Build();
}
}
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:persian="clr-namespace:MauiPersianToolkit.Controls;assembly=MauiPersianToolkit"
x:Class="YourApp.MainPage"
Title="Persian Toolkit Demo">
<ScrollView>
<StackLayout Padding="20" Spacing="15">
<!-- Persian DatePicker - Single Selection -->
<Label Text="Persian DatePicker (Single)" FontSize="16" FontAttributes="Bold"/>
<persian:DatePicker
PlaceHolder="Select Date"
SelectedPersianDate="{Binding SelectedDate}"
CalendarType="Persian"
DisplayFormat="yyyy/MM/dd" />
<!-- Gregorian DatePicker -->
<Label Text="Gregorian DatePicker" FontSize="16" FontAttributes="Bold"/>
<persian:DatePicker
PlaceHolder="Select Date"
SelectedPersianDate="{Binding SelectedGregorianDate}"
CalendarType="Gregorian"
DisplayFormat="yyyy/MM/dd" />
<!-- Islamic (Hijri) DatePicker -->
<Label Text="Islamic DatePicker" FontSize="16" FontAttributes="Bold"/>
<persian:DatePicker
PlaceHolder="Select Date"
SelectedPersianDate="{Binding SelectedHijriDate}"
CalendarType="Hijri"
DisplayFormat="yyyy/MM/dd" />
<!-- Entry Control -->
<Label Text="Entry Field" FontSize="16" FontAttributes="Bold"/>
<persian:EntryView
PlaceHolder="Enter your name"
Text="{Binding UserName}" />
<!-- Expander Control -->
<Label Text="Expandable Section" FontSize="16" FontAttributes="Bold"/>
<persian:Expander IsExpanded="False" Header="Click to expand">
<Label Text="This content is hidden until expanded" Padding="10"/>
</persian:Expander>
</StackLayout>
</ScrollView>
</ContentPage>
using MauiPersianToolkit.Services.Calendar;
using MauiPersianToolkit.Enums;
// Get calendar service
var persianService = CalendarServiceFactory.GetService(CalendarType.Persian);
var gregorianService = CalendarServiceFactory.GetService(CalendarType.Gregorian);
var hijriService = CalendarServiceFactory.GetService(CalendarType.Hijri);
// Convert dates
var today = DateTime.Now;
string persianDate = persianService.ToCalendarDate(today); // "1403/05/25"
string gregorianDate = gregorianService.ToCalendarDate(today); // "2024/08/16"
string hijriDate = hijriService.ToCalendarDate(today); // "1446/02/21"
// Parse dates back
var parsed = persianService.ToGregorianDate("1403/05/25");
// Get calendar information
int year = persianService.GetYear(today);
int month = persianService.GetMonth(today);
string monthName = persianService.GetMonthName(month);
bool isLeap = persianService.IsLeapYear(year);
DayOfWeek holiday = persianService.GetLastDayOfWeek(); // Friday for Persian
using MauiPersianToolkit;
DateTime today = DateTime.Now;
// Convert to Persian (default)
string persianDate = today.ToPersianDate(); // "1403/05/25"
// Convert to other calendars
string gregorianDate = today.ToCalendarDate(CalendarType.Gregorian);
string hijriDate = today.ToCalendarDate(CalendarType.Hijri);
// Parse back
var parsed = "1403/05/25".ToDateTime();
var gregorianParsed = "2024/08/16".ToDateTime(CalendarType.Gregorian);
using MauiPersianToolkit.Services.Dialog;
using MauiPersianToolkit.Models;
public partial class MainPage : ContentPage
{
private readonly IDialogService _dialogService;
public MainPage(IDialogService dialogService)
{
InitializeComponent();
_dialogService = dialogService;
}
// Alert Dialog
private async void ShowAlert()
{
await _dialogService.Alert("This is an alert message");
}
// Confirm Dialog
private async void ShowConfirm()
{
var config = new ConfirmConfig
{
Title = "Confirm Action",
Message = "Are you sure?",
AcceptText = "Yes",
CancelText = "No",
OnAction = (result) =>
{
if (result)
Debug.WriteLine("User confirmed");
else
Debug.WriteLine("User cancelled");
}
};
await _dialogService.Confirm(config);
}
// Prompt Dialog
private async void ShowPrompt()
{
var config = new PromptConfig
{
Title = "Enter Name",
Message = "Please enter your name:",
Placeholder = "Name",
AcceptText = "OK",
CancelText = "Cancel",
OnAction = (result) =>
{
if (result.IsOk)
Debug.WriteLine($"User entered: {result.Input}");
}
};
await _dialogService.Prompt(config);
}
// Custom Dialog
private async void ShowCustomDialog()
{
var customContent = new StackLayout
{
Children =
{
new EntryView { PlaceHolder = "Name" },
new EntryView { PlaceHolder = "Email" },
new persian:DatePicker { PlaceHolder = "Birth Date" }
}
};
var config = new CustomDialogConfig
{
Title = "Register",
Message = "Enter your information",
Content = customContent,
AcceptText = "Register",
CancelText = "Cancel",
OnAction = (result) =>
{
Debug.WriteLine($"Dialog result: {result}");
}
};
await _dialogService.CustomDialog(config);
}
}
See MauiPersianToolkit/Examples/CalendarServiceExamples.cs for:
The project includes comprehensive unit tests:
CalendarServiceTests - 7 tests covering:
CalendarWeekLayoutTests - 13+ tests covering:
Run tests:
dotnet test ./MauiPersianToolkit.Test/MauiPersianToolkit.Test.csproj
All controls are designed to be easily customizable:
Implement ICalendarService for custom calendar support:
public class MyCustomCalendarService : ICalendarService
{
// Implement interface methods
public string ToCalendarDate(DateTime gregorianDate) { /* ... */ }
public DateTime ToGregorianDate(string calendarDate) { /* ... */ }
// ... other methods
}
// Register with factory
CalendarServiceFactory.RegisterService(
CalendarType.Custom,
new MyCustomCalendarService()
);
Customize colors, fonts, and behaviors:
<persian:DatePicker
PlaceHolder="Select Date"
SelectDayColor="Blue"
CanSelectHolidays="False"
DisplayFormat="yyyy/MM/dd" />
The project includes a comprehensive test suite:
MauiPersianToolkit.Test/
โโโ CalendarServiceTests.cs (7 tests)
โโโ CalendarWeekLayoutTests.cs (13+ tests)
โโโ CalendarWeekLayoutTests.README.md (documentation)
Automated testing on every commit:
See .github/workflows/ for CI/CD configuration.
This project is licensed under the MIT License - see the LICENSE file for details.
We welcome contributions! Follow these steps:
git checkout -b feature/YourFeature)git commit -m 'Add YourFeature')git push origin feature/YourFeature)| Component | Status | Coverage |
|---|---|---|
| Core Library | โ Stable | Mature |
| Calendar System | โ Stable | 3 calendars |
| UI Controls | โ Stable | 10+ controls |
| Dialog System | โ Stable | 4 types |
| Unit Tests | โ Complete | 20+ tests |
| Documentation | โ Complete | Full |
Happy Coding! ๐
Start building beautiful Persian-enabled applications with MauiPersianToolkit today!