LazyApiPack.Mvvm 0.0.6

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

// Install LazyApiPack.Mvvm as a Cake Tool
#tool nuget:?package=LazyApiPack.Mvvm&version=0.0.6                

About this pack

Supports MVVM functionality for applications.

Overview

The framework is currently under development. Breaking changes may occur!

Basic functions

  • View - ViewModel -Model pattern
  • Services (Dependency Injection) in ViewModels and Services
  • Stores
  • Regions
  • Modules
  • Communication between modules
  • Multilingual

Application scaffold

App.cs

The application derives from MvvmApplication and needs the OnSetup method overridden.

public partial class App : Application
{
    public App() : base()
    {
      var app = new MvvmApp();
      MainWindow = (Window)app.Setup();
    }
}

public class MvvmApp : MvvmApplication {
    protected override void OnSetup(MvvmApplicationConfiguration configuration)
    {
        configuration
            .WithModule<NeuralFireworksModule>()
            .WithShellWindow<MainWindow>()
            .WithSplashWindow<SplashWindow>();

                
    }
}

The application itself hosts one or more modules that implement the business logic. The application itself only provides platform specific code such as Dialog Windows, Shell Window and SplashScreen

All Windows must implement the IWindowTemplate / ISplashScreenTemplate interface.

Module.cs

public class NeuralFireworksModule : MvvmModule
{
    private string _moduleId = "net.thelazycrazybrain.NeuralFireworks.Module.NeuralFireworksModule";
    public override string ModuleId { get => _moduleId; }

    public override void OnSetup(MvvmModuleConfiguration configuration)
    {
        configuration
            .WithStore(new SolutionStore())
            .WithModule<IronPythonModule>()

            .WithViews("NeuralFireworks.Module.Views")
            .WithViewModels("NeuralFireworks.Module.ViewModels")

            .WithLocalizationNamespaces(typeof(NeuralFireworksModule).Assembly, new[] { "NeuralFireworks.Module.Localizations" })

            .WithService<ILocalizationService, LocalizationService>()
            .WithService<ILogger, FileLogger>()
            .WithService<IAINetworkService, AINetworkService>(true)

            .WithRegionAdapter<MultiWindowRegionAdapter>()
            .WithRegionAdapter<ContentControlRegionAdapter>()
            .WithRegionAdapter<TabControlRegionAdapter>()
            .WithRegionAdapter<CloseableTabControlRegionAdapter>();
    }
    public override void OnSetupComplete()
    {
        MvvmApplication.Instance.NavigateTo("InterpreterViewModel", "ModalRegion", null, null);
        MvvmApplication.Instance.NavigateTo("DebugViewModel", "Main", null, null);

    }
}

The module itself configures the application.

TBD

Caption of a view

If you want to support a caption for a view (to show in a tab), use the MVVM Caption Pattern

Patterns

MVVM Caption Pattern

To get a caption of a view (for example - to show in a tab), use this pattern.

Class Layout:

public class MyView : UserControl 
{
    public MyView() {
        DataContext = new MyViewModel();
    }

    public override string ToString() {
        return "MyView";
    }
}

public class MyViewModel : ISupportModel {
    public MyViewModel() {
        Model = new MyModel();
    }

    public string Title { get; } = "My ViewModel Title";
}

public class MyModel  {
    public string Caption { get; } = "My Model Title";
}

public class MyModelDataContext {

}

Call:

string caption = AppLocalizationManager.Instance.GetMvvmCaption(view);

Result:

  • The result of the call and this class layout would be "My Model Title".
  • If the Caption property of MyModel would not exist or would return null, the result would be "My ViewModel Title".
  • If the Title property of MyViewModel were null, the result would be "MyView", because the method ToString() is overridden.
  • If the method ToString() was not overridden, the result would be null.

Pattern:

The process goes down in the class hierarchy and then checks, if that class inherits either from ISupportModel (Property: Model) or from FrameworkElement (Property: DataContext) looks for the properties "Caption" (Public, Not-Static), "Title" (Public, Not-Static) and the ToString() method (overridden!). If the properties are not found or null, the process goes up one step in the hierarchy and looks for that pattern there until it reaches the topmost element (view).

Example:

Alt text

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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 (1)

Showing the top 1 NuGet packages that depend on LazyApiPack.Mvvm:

Package Downloads
LazyApiPack.Mvvm.Wpf

Provides an MVVM pattern for WPF applications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.6 241 11/21/2023

Ported to .net core