Skip to content

ConvMVVM2 (Convergence MVVM2) is free MVVM library for WPF inspired by Community Toolkit library and Prism frameworks.

Notifications You must be signed in to change notification settings

gellston/ConvMVVM2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

ConvMVVM2.Core latest version downloads

ConvMVVM2.WPF latest version downloads

ConvMVVM2

ConvMVVM2 (Convergence MVVM2) is free MVVM library inspired by Community Toolkit library and Prism frameworks.

Supported .NET Runtime

  • .NET Framework 4.8
  • .NET Framework 4.8.1
  • .NET 6
  • .NET 7
  • .NET 8
  • .NET 9

Overview

Host Template

[STAThread]
public static void Main(string[] args)
{
    var host = ConvMVVM2.WPF.Host.ConvMVVM2Host.CreateHost<BootStrapper, Application>(args, "HostTemplate");
    host.Build()
        .ShutdownMode(ShutdownMode.OnMainWindowClose)
        .Popup<MainWindow>(dialog: true)
        //.Popup("MainWindow")
        .RunApp();

}

It support host object creation with generic template and also popup window selectively

BootStrapper

public class BootStrapper : AppBootstrapper
{
    protected override void OnStartUp()
    {
      
    }

    protected override void RegionMapping(IRegionManager layerManager)
    {
        layerManager.Mapping<MainView>("MainView");
    }

    protected override void RegisterModules()
    {
    
    }

    protected override void RegisterServices(IServiceCollection serviceCollection)
    {
        serviceCollection.AddSingleton<MainWindow>();

        serviceCollection.AddSingleton<MainViewModel>();
        serviceCollection.AddSingleton<SubViewModel>();

        serviceCollection.AddSingleton<MainView>();
        serviceCollection.AddSingleton<SubView>();
    }

    protected override void ViewModelMapping(IViewModelMapper viewModelMapper)
    {
        
    }
}

Bootstrapper support ioc, module, viewmodel mapping and region mapping.

Property

#region Public Property
[Property]
private string _TestText = "test";
#endregion

#region Event Handler
partial void OnTestTextChanged(string oldValue, string newValue)
{
    
}
partial void OnTestTextChanged(string value)
{
   
}
partial void OnTestTextChanging(string oldValue, string newValue)
{

}
partial void OnTestTextChanging(string value)
{

}
#endregion

RelayCommand

[RelayCommand]
private void Test()
{
    try
    {

    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine(ex.ToString());
    }
}

[AsyncRelayCommand]
private async Task Test2()
{
    try
    {

    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine(ex.ToString());
    }
}

It support RelayCommand and AsyncRelayCommand also support source generator for them

ViewModelLocator

<UserControl x:Class="BootStrapperApp.Views.MainView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:BootStrapperApp.Views"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800"
             xmlns:convMVVM2="https://github.com/gellston/ConvMVVM2"
             convMVVM2:ViewModelLocator.AutoWireViewModel="True"
             convMVVM2:ViewModelLocator.UseNamePatternMapper="True"
             convMVVM2:ViewModelLocator.UseViewModelMapper="False">
    
</UserControl>

ViewModelLocator support autowire viewmodel with using name pattern mapping and manual mapping

RegionManager

<Window x:Class="BootStrapperApp.Windows.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:BootStrapperApp.Windows"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800"
        xmlns:convMVVM2="https://github.com/gellston/ConvMVVM2"
        >

    <convMVVM2:WPFRegion RegionName="MainView"></convMVVM2:WPFRegion>
</Window>
[RelayCommand]
private void Test()
{
    try
    {
        this.regionManager.Navigate("MainView", "SubView");
    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine(ex.ToString());
    }
}

To use regionManager, it need to place RegionControl on somewhere

LocalizeService

<!-- MainView -->
<UserControl x:Class="LocalizeApp.Views.MainView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:LocalizeApp.Views"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800"
             xmlns:convMVVM2="https://github.com/gellston/ConvMVVM2">
    <DockPanel Background="Orange">
        <Button DockPanel.Dock="Bottom"
                Height="50"
                Content="Change Local"
                FontSize="35"
                Command="{Binding TestCommand}"></Button>
        <TextBlock Text="{convMVVM2:Localize TestString}"></TextBlock>
    </DockPanel>
</UserControl>
//MainViewModel
[RelayCommand]
private void Test()
{
    try
    {
        this.switchLocal = !this.switchLocal;

        if (this.switchLocal)
            this.localizeService.ChangeLocal("en");
        else
            this.localizeService.ChangeLocal("kr");
    }
    catch
    {

    }
}
// BootStrapper
protected override void OnStartUp(IServiceContainer container)
{
    var localizeService = container.GetService<ILocalizeService>();
    localizeService.SetResourceManager(Properties.Resource.ResourceManager);
    
}

it can change local setting easily from resource manager

Module

//BootStrapper
public class BootStrapper : AppBootstrapper
{
    protected override void OnStartUp(IServiceContainer container)
    {

    }

    protected override void RegionMapping(IRegionManager layerManager)
    {

    }

    protected override void RegisterModules()
    {
        this.EnableAutoModuleSearch(true);
        this.AddModuleRelativePath("Modules");
    }

    protected override void RegisterServices(IServiceCollection serviceCollection)
    {
        serviceCollection.AddSingleton<MainWindow>();
    }

    protected override void ViewModelMapping(IViewModelMapper viewModelMapper)
    {
    }
}
//AModule
public class Module : IModule
{
    public string ModuleName => "AModule";
    public string ModuleVersion => "1.0";
    public void OnStartUp(IServiceContainer container)
    {
    }
    public void RegionMapping(IRegionManager layerManager)
    {
        layerManager.Mapping<AView>("ContentView");
    }
    public void RegisterServices(IServiceCollection container)
    {
        container.AddSingleton<AView>();

        container.AddSingleton<AViewModel>();
    }
    public void ViewModelMapping(IViewModelMapper viewModelMapper)
    {
    }
}
# Post Build Script to move module dll in Modules folder
if not exist "$(SolutionDir)\\ModuleApp\\bin\\$(ConfigurationName)\\net9.0-windows\\Modules" mkdir "$(SolutionDir)\\ModuleApp\\bin\\$(ConfigurationName)\\net9.0-windows\\Modules"
xcopy "$(SolutionDir)\\AModule\\bin\\$(ConfigurationName)\\net9.0-windows\\" "$(SolutionDir)\\ModuleApp\\bin\\$(ConfigurationName)\\net9.0-windows\\Modules\\" /c /i /e /h /y
xcopy "$(SolutionDir)\\BModule\\bin\\$(ConfigurationName)\\net9.0-windows\\" "$(SolutionDir)\\ModuleApp\\bin\\$(ConfigurationName)\\net9.0-windows\\Modules\\" /c /i /e /h /y
xcopy "$(SolutionDir)\\CModule\\bin\\$(ConfigurationName)\\net9.0-windows\\" "$(SolutionDir)\\ModuleApp\\bin\\$(ConfigurationName)\\net9.0-windows\\Modules\\" /c /i /e /h /y
xcopy "$(SolutionDir)\\MainModule\\bin\\$(ConfigurationName)\\net9.0-windows\\" "$(SolutionDir)\\ModuleApp\\bin\\$(ConfigurationName)\\net9.0-windows\\Modules\\" /c /i /e /h /y

ConvMVVM2 also support modulus development

License

The MIT License (MIT)

Copyright (c) 2022-present ConvMVVM Development Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

TOP

About

ConvMVVM2 (Convergence MVVM2) is free MVVM library for WPF inspired by Community Toolkit library and Prism frameworks.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages