Go to content

Bulletcode.NET

MVVM

Bulletcode.NET contains a Bulletcode.UI package for building cross-platform desktop and mobile applications using the MVVM architecture, based on the .NET MAUI framework. See the Introduction for more information about installing the Bulletcode.NET NuGet packages.

Application builder

Applications which use Bulletcode.UI should call Application.CreateBuilder() instead of MauiApp.CreateBuilder() in their MauiProgram.cs:

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = Application.CreateBuilder( GetEnvironmentName() );

        builder.UseMauiApp<App>();

#if DEBUG
        builder.Logging.AddDebug();
#endif
        builder.Logging.AddTextFile();

        return builder.Build();
    }

    private static string GetEnvironmentName()
    {
#if DEBUG
        return Environments.Development;
#else
        return Environments.Production;
#endif
    }
}

The environment name defaults to Production, but you can change the environment depending on build configuration. For example, the Development environment can be used in Debug builds. A Test build can also be configured if necessary. See Configuration for more information about configuration files used by Bulletcode.UI applications.

The logging builder is initialized using the "Logging" section of the configuration. No logging providers are registered by default. The AddTextFile() extension method for ILoggingBuilder registers the text file logging provider. See Logging for more information.

Both the IHostEnvironment and IConfiguration are added as singletons to the service provider. The services required for logging and managing options are also registered. See Dependency Injection for more information. A basic executor for background services implementing IHostedService is also configured.

Generic theme

The application must include the Generic theme from Bulletcode.UI in its resource dictionary:

<Application
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:themes="clr-namespace:Bulletcode.UI.Themes;assembly=Bulletcode.UI"
    x:Class="App.UI.App"
    >
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <themes:Generic/>
                <!-- add application specific styles -->
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

View models

The BaseViewModel, ObservableValidator and ObservableObject classes can be used as base classes for your view models. See View Models for more information.

In addition, Bulletcode.UI includes two classes which can be used as base classes for view models for shell pages (BasePageViewModel) and dialogs (BaseDialogViewModel). Both these classes inherit from BaseViewModel. See Shell for more information about creating pages and dialogs.