zoft.MauiExtensions.Core 4.0.0

dotnet add package zoft.MauiExtensions.Core --version 4.0.0                
NuGet\Install-Package zoft.MauiExtensions.Core -Version 4.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="zoft.MauiExtensions.Core" Version="4.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add zoft.MauiExtensions.Core --version 4.0.0                
#r "nuget: zoft.MauiExtensions.Core, 4.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install zoft.MauiExtensions.Core as a Cake Addin
#addin nuget:?package=zoft.MauiExtensions.Core&version=4.0.0

// Install zoft.MauiExtensions.Core as a Cake Tool
#tool nuget:?package=zoft.MauiExtensions.Core&version=4.0.0                

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

Create Windows MainThreadService

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;
    }
}

Register MainThreadService depending on platform

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();

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

</br>

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>

</br>

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:

public sealed class WindowsMainThreadService : MainThreadService
{
    protected override DispatcherQueue MainThreadDispatcher => WinUI.App.Dispatcher;
}

</br>

Base Models

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 the INotifyPropertyChanged interface
  • ZoftObservableRecipient: Based on the ObservableRecipient class, provides a base implementation of the ObservableRecipient class
  • ZoftObservableValidator: Based on the ObservableValidator class, provides a base implementation of the ObservableValidator class
    • Override OnErrorsChanged to handle logic when the validation results change

</br>

Busy Notification Management

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

</br>

Weak Subscription

The package provides a set of extension methods to subscribe to events using weak references, avoiding memory leaks when the subscriber is not disposed.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-android34.0 is compatible.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-ios17.5 is compatible.  net8.0-maccatalyst was computed.  net8.0-maccatalyst17.5 is compatible.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net8.0-windows10.0.19041 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on zoft.MauiExtensions.Core:

Package Downloads
zoft.MauiExtensions.Controls.AutoCompleteEntry

.Net MAUI Entry control that provides a list of suggestions as the user types.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.0 207 9/19/2024
3.1.0 122 9/6/2024
3.0.0 4,362 12/25/2023
2.0.2 881 4/13/2023
2.0.1 518 4/13/2023
2.0.0 7,156 4/6/2023
1.2.0 1,164 12/7/2022
1.1.0 701 12/6/2022
1.1.0-pre001 522 12/6/2022
1.0.8 697 12/6/2022
1.0.7 700 12/5/2022
1.0.6 739 11/28/2022
1.0.5 671 11/27/2022
1.0.4 678 11/24/2022
1.0.3 736 11/24/2022
1.0.2 701 11/7/2022
1.0.1 793 10/20/2022
1.0.0 784 8/29/2022
1.0.0-RC1 127 5/6/2022
1.0.0-alfa.4 143 10/11/2021
1.0.0-alfa.3 143 9/22/2021
1.0.0-alfa.2 192 7/15/2021
1.0.0-alfa.1 195 6/24/2021

Deprecated DependsOn and ValidationObject.
Futher usage of the CommunityToolkit.MVVM base classes.
Added 3 wrappers for the Observable models of CommunityToolkit.MVVM.
Removed the CoreViewModel