CommonHelpers.Maui 0.5.2

dotnet add package CommonHelpers.Maui --version 0.5.2
                    
NuGet\Install-Package CommonHelpers.Maui -Version 0.5.2
                    
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="CommonHelpers.Maui" Version="0.5.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CommonHelpers.Maui" Version="0.5.2" />
                    
Directory.Packages.props
<PackageReference Include="CommonHelpers.Maui" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CommonHelpers.Maui --version 0.5.2
                    
#r "nuget: CommonHelpers.Maui, 0.5.2"
                    
#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.
#addin nuget:?package=CommonHelpers.Maui&version=0.5.2
                    
Install as a Cake Addin
#tool nuget:?package=CommonHelpers.Maui&version=0.5.2
                    
Install as a Cake Tool

CommonHelpers.Maui

This is a library containing some commonly needed helpers for .NET MAUI C#/XAML projects. The goal is to build on top of the more popular CommonHelpers package, but with .NET MAUI-specialized functionality.

Package NuGet.org Features & Docs
CommonHelpers.Maui # README

Features

Behaviors

A BehaviorBase<T> class that lets you create your own, or use the out-of-the-box EventToCommandBehavior implementation. To get started, Add the XML namespace to the view:

xmlns:behaviors="clr-namespace:CommonHelpers.Maui.Behaviors;assembly=CommonHelpers.Maui"
<SomeControl x:Name="MyControl">
    <SomeControl.Behaviors>
        <behaviors:EventToCommandBehavior EventName="Clicked" Command="{Binding MyCommand}">
    </SomeControl.Behaviors>
</SomeControl>

MVVM Helpers

The ContentPageBase and PageViewModelBase allows you to use view lifecycle events safely in your view model!

Inherit your page from ContentPageBase instead of ContentPage, like this:

public partial class MainPage : ContentPageBase
{
    public MainPage(MainPageViewModel vm)
    {
        InitializeComponent();
        BindingContext = new MainPageViewModel();
    }
}

Inherit your viewmodel from the PageViewModelBase

public class public class MainPageViewModel : PageViewModelBase
{
}

and you can now override any of these view methods:

public class public class MainPageViewModel : PageViewModelBase
{
    public override void OnAppearing()
    {
    }

    public override void OnDisappearing()
    {
    }

    public override void OnNavigatingFrom(NavigatingFromEventArgs args)
    {
        base.OnNavigatingFrom(args);
    }

    public override void OnNavigatedFrom(NavigatedFromEventArgs args)
    {
        base.OnNavigatedFrom(args);
    }

    public override void OnNavigatedTo(NavigatedToEventArgs args)
    {
        base.OnNavigatedTo(args);
    }

    public override bool OnBackButtonRequested()
    {
        return base.OnBackButtonRequested();
    }
}

Converters

The library has some commonly needed value converters. To get started, Add the XML namespace to the view:

xmlns:converters="clr-namespace:CommonHelpers.Maui.Converters;assembly=CommonHelpers.Maui"

Now you can use any of these IValueConverter implementations:

  • IntToDoubleConverter
  • InvertBoolConverter
  • NullToBoolConverter
  • StringToUriConverter

As well as some boutique ones:

  • ConfigurableBoolConverter
<Grid>
    <Grid.Resources>
        <converters:ConfigurableBoolConverter x:Key="InvertBoolConv"
                                              x:TypeArguments="x:Boolean"
                                              TrueResult="False"
                                              FalseResult="True" />
    </Grid.Resources>

    <Label IsVisible="{Binding HasItems, Converter={StaticResource InvertBoolConv}}"
           Text="No Items!" />
<Grid>
  • NameToInitialsConverter
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:converters="clr-namespace:CommonHelpers.Maui.Converters;assembly=CommonHelpers.Maui"
             x:Class="YourApp.MainPage">
    <Grid>
        <ContentPage.Resources>
            <converters:NameToInitialsConverter x:Key="NameToInitialsConv">
        </ContentPage.Resources>

        <Label Text="{Binding FullName, Converter={StaticResource NameToInitialsConv}}"/>
    </Grid>
</ContentPage>

MauiApp Extensions

Extensions for platform-specific code that can be used in MauiProgram.cs.

  • For WinUI
    • window.TryMicaOrAcrylic();
  • For MacCatalyst
    • windowScene.RestrictWindowMinimumSize(new CGSize(600, 400))
    • windowScene.RestrictWindowMaximumSize(new CGSize(1920, 1080))
    • windowScene.RestrictWindowSize(new CGSize(600, 400), new CGSize(1920, 1080))
#if WINDOWS10_0_17763_0_OR_GREATER
using CommonHelpers.Maui.Platforms.Windows;

#elif MACCATALYST
using CommonHelpers.Maui.Platforms.MacCatalyst;
using UIKit;
using CoreGraphics;

#endif

public static MauiApp CreateMauiApp()
{
    // ... your other boiler plate startup code here

    builder.ConfigureLifecycleEvents(events =>
    {
    
#if WINDOWS10_0_17763_0_OR_GREATER
        events.AddWindows(wndLifeCycleBuilder =>
        {
            wndLifeCycleBuilder.OnWindowCreated(window =>
            {
                // For automatic Mica or Acrylic support
                window.TryMicaOrAcrylic();
            });
        });
    });
    
#elif MACCATALYST
    events.AddiOS(wndLifeCycleBuilder =>
    {
        wndLifeCycleBuilder.SceneWillConnect((scene, session, options) =>
        {
            if (scene is UIWindowScene windowScene)
            {
                // Can be used for restricting the MacOS window's min, max (or both) size.
                windowScene.RestrictWindowMinimumSize(new CGSize(600, 400));
            }
        });
    });
#endif
    return builder.Build();
}

More to come

This is only the beginning, I plan to build this out as an indispensable companion to the already fantastic CommonHelpers library.

Product Compatible and additional computed target framework versions.
.NET net8.0-android34.0 is compatible.  net8.0-ios18.0 is compatible.  net8.0-maccatalyst18.0 is compatible.  net8.0-windows10.0.19041 is compatible.  net8.0-windows10.0.22621 is compatible.  net9.0-android was computed.  net9.0-android35.0 is compatible.  net9.0-ios was computed.  net9.0-ios18.0 is compatible.  net9.0-maccatalyst was computed.  net9.0-maccatalyst18.0 is compatible.  net9.0-windows was computed.  net9.0-windows10.0.19041 is compatible.  net9.0-windows10.0.22621 is compatible.  net10.0-android was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.5.2 128 6/23/2025
0.5.1 70 6/20/2025
0.5.0 347 4/2/2025
0.4.0 183 12/27/2024
0.2.0 272 7/28/2023
0.1.0 272 3/14/2023

Review releases on GitHub at bit.ly/CommonHelpers