CommonHelpers.Maui 0.2.0

dotnet add package CommonHelpers.Maui --version 0.2.0                
NuGet\Install-Package CommonHelpers.Maui -Version 0.2.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="CommonHelpers.Maui" Version="0.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CommonHelpers.Maui --version 0.2.0                
#r "nuget: CommonHelpers.Maui, 0.2.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 CommonHelpers.Maui as a Cake Addin
#addin nuget:?package=CommonHelpers.Maui&version=0.2.0

// Install CommonHelpers.Maui as a Cake Tool
#tool nuget:?package=CommonHelpers.Maui&version=0.2.0                

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>

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 net6.0 is compatible.  net6.0-android was computed.  net6.0-android31.0 is compatible.  net6.0-ios was computed.  net6.0-ios16.1 is compatible.  net6.0-maccatalyst was computed.  net6.0-maccatalyst16.1 is compatible.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net6.0-windows10.0.19041 is compatible.  net7.0 is compatible.  net7.0-android was computed.  net7.0-android33.0 is compatible.  net7.0-ios was computed.  net7.0-ios16.1 is compatible.  net7.0-maccatalyst was computed.  net7.0-maccatalyst16.1 is compatible.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net7.0-windows10.0.19041 is compatible.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.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.2.0 251 7/28/2023
0.1.0 220 3/14/2023

Review releases on GitHub at bit.ly/CommonHelpers