Set of tools designed to be used in MAUI projects, including Views, ViewModels, Services, Extensions and more...
Nuget Package | Current Version |
---|---|
zoft.MauiExtensions.Core |
Install nuget package: zoft.MauiExtensions.Core
Install-Package zoft.MauiExtensions.Core
using Microsoft.UI.Dispatching;
using zoft.MauiExtensions.Core.Services;
namespace <your.app.base.namespace>.Platforms.Windows.Services
{
public sealed class WindowsMainThreadService : MainThreadService
{
protected override DispatcherQueue MainThreadDispatcher => WinUI.App.Dispatcher;
}
}
return builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
})
#if WINDOWS
.Services.AddSingleton<IMainThreadService, Platforms.Windows.Services.WindowsMainThreadService>();
#else
.Services.AddSingleton<IMainThreadService, MainThreadService>();
#endif
.Build();
Refer to the sample to have a better understanding of package capabilities. Bellow you can find the most common features and how to use them
The package provides a set of tools to implement localization in your app:
ILocalizationService
: Interface for the localization service. The interface exists to make it easier to use iwith IOC and to override the base implementationResourceManagerLocalizationService
: Implementation of theILocalizationService
using resource files (.resx)
builder.Services.AddSingleton<ILocalizationService>(new ResourceManagerLocalizationService(AppResources.ResourceManager, SupportedLanguages.DefaultLanguage));
TranslationMarkup
: XAML markup that provides an easy way to apply the translation directly in XAML
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:zoft="http://zoft.maui.extensions"
x:Class="zoft.MauiExtensions.Sample.Views.LocalizationView"
Title="{zoft:Translate LocalizationPage_Title}">
...
...
<ScrollView>
<VerticalStackLayout Spacing="10">
<Label Text="{zoft:Translate LocalizationPage_Label1}" FontSize="16" FontAttributes="Bold"/>
<Label Text="{zoft:Translate LocalizationPage_Label2}" />
<Label Text="{zoft:Translate LocalizationPage_Label3}" FontAttributes="Italic" BackgroundColor="LightGray"/>
</VerticalStackLayout>
</ScrollView>
...
</ContentPage>
At current time, the MAUI essentials implementation of MainThread
is not working for Windows. This package provides a wrapper interface IMainThreadService
and an implementation for all platforms, including Windows.
To use, you just need to register the correct service depending of the platform:
public sealed class WindowsMainThreadService : MainThreadService
{
protected override DispatcherQueue MainThreadDispatcher => WinUI.App.Dispatcher;
}
Based on the Component Models of the CommunityToolkit.MVVM, the package provides a set of base models that can be used to create Models, ViewModels and Services in your app.
- ZoftObservableObject: Based on the
ObservableObject
class, provides a base implementation of theINotifyPropertyChanged
interface - ZoftObservableRecipient: Based on the
ObservableRecipient
class, provides a base implementation of theObservableRecipient
class - ZoftObservableValidator: Based on the
ObservableValidator
class, provides a base implementation of theObservableValidator
class- Override
OnErrorsChanged
to handle logic when the validation results change
- Override
Base models provide methods to execute code in a background thread, while providing with updated on IsBusy
and BusyMessage
properties that can be bound to an UI element (i.e. ActivityIndicator
)
await DoWorkAsync(() => ..., "Busy Message");
var result = await DoWorkAsync(() => return some_object, "BusyMessage");
The package provides a set of extension methods to subscribe to events using weak references, avoiding memory leaks when the subscriber is not disposed.