Skip to main content
net6.0net6.0-android31.0net6.0-ios16.0net6.0-maccatalyst15.4net6.0-windows10.0.19041

Extension library built on top of MAUI. Provides extra functionalities for ViewModels and Services, including: - Dependency notification propagation via attributes - WeakSubscriptions - Command and AsyncCommand

Published
Dec 6, 2022
3y ago
Total Downloads
49.8K
49,762

Install

dotnet add package zoft.MauiExtensions.Core --version 1.1.0-pre001
ProductVersions
.NET
net6.0net6.0-android31.0net6.0-ios16.0net6.0-maccatalyst15.4net6.0-windows10.0.19041

README

zoft.MauiExtensions

Set of tools designed to be used in MAUI projects, including Views, ViewModels, Services, Extensions and more...

Nuget Package Current Version
zoft.MauiExtensions.Core NuGet

Getting Started

Install nuget package: zoft.MauiExtensions.Core

Install-Package zoft.MauiExtensions.Core

How To Use

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

Localization Service

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 implementation
  • ResourceManagerLocalizationService: Implementation of the ILocalizationService 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>

MainThread Service

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:

private static MauiAppBuilder RegisterServices(this MauiAppBuilder builder)
{
    #if WINDOWS
    builder.Services.AddSingleton<IMainThreadService, Platforms.Windows.Services.WindowsMainThreadService>();
    #else
    builder.Services.AddSingleton<IMainThreadService, MainThreadService>();
    #endif

    return builder;
}

CoreViewModel

The CoreViewModel provides a set of base implementations to use in ViewModels. This implementation is built on top of CommunityToolikt.Mvvm.ObservableObject. It also uses other CommunityToolkit capabilities, like the ObservableProperty.

Dependency Management

Allows the configuration of properties and/or methods to react on PropertyChangeEvent of a specific property

public partial class DependsOnViewModel : CoreViewModel
{
    [ObservableProperty]
    private string _triggerText;

    [DependsOn(nameof(TriggerText))]
    public string TargetText => $"TargetText triggered '{TriggerText}'";

    [ObservableProperty]
    private DateTime _targetDate = DateTime.Now;

    [DependsOn(nameof(TriggerText))]
    protected void OnTriggerTextChanged()
    {
        TargetDate = TargetDate.AddDays(1);
    }

}
Busy Notification Management

Base 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");

Validation Models

tbd...

Changes from Previous Version

No structural changes between v1.0.8 and v1.1.0-pre001.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 5 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.