All Projects → thomasclaudiushuber → mvvmgen

thomasclaudiushuber / mvvmgen

Licence: MIT license
MvvmGen is a lightweight MVVM library for XAML applications. It generates your ViewModels on-the-fly for you via a Roslyn-based C# Source Generator.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to mvvmgen

ModernWpf
Modern styles and controls for your WPF applications without need WinRT
Stars: ✭ 65 (-63.69%)
Mutual labels:  xaml, wpf, winui
Rapid Xaml Toolkit
Tools to accelerate XAML development within Visual Studio.
Stars: ✭ 427 (+138.55%)
Mutual labels:  xaml, wpf, xamarin-forms
Xamlcss
Style Xaml applications with CSS
Stars: ✭ 271 (+51.4%)
Mutual labels:  xaml, wpf, xamarin-forms
dotnet
.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
Stars: ✭ 865 (+383.24%)
Mutual labels:  wpf, maui, uno-platform
Xaml Code Experiences
A collection of the experiences I have collected during days of Xamarin and Wpf, while following the MVVM design pattern.
Stars: ✭ 114 (-36.31%)
Mutual labels:  xaml, wpf, xamarin-forms
arcgis-runtime-demos-dotnet
Demo applications provided by the ArcGIS Runtime SDK for .NET Team
Stars: ✭ 51 (-71.51%)
Mutual labels:  xaml, wpf, xamarin-forms
Ammyui
Ammy language repository
Stars: ✭ 356 (+98.88%)
Mutual labels:  xaml, wpf, xamarin-forms
Uno.Themes
This library is designed to help you use the material design system with the Uno Platform
Stars: ✭ 112 (-37.43%)
Mutual labels:  xaml, uno-platform, winui
Mahapps.metro
A framework that allows developers to cobble together a better UI for their own WPF applications with minimal effort.
Stars: ✭ 8,023 (+4382.12%)
Mutual labels:  xaml, wpf, winui
Formswpflive
Live XAML development for Xamarin Forms Apps using WPF Backend.
Stars: ✭ 14 (-92.18%)
Mutual labels:  xaml, wpf, xamarin-forms
Arcgis Runtime Samples Dotnet
Sample code for ArcGIS Runtime SDK for .NET – UWP, WPF, Xamarin.Android, Xamarin.iOS, and Xamarin.Forms
Stars: ✭ 274 (+53.07%)
Mutual labels:  xaml, wpf, xamarin-forms
EBind
🔵 .NET Data Binding we deserve: concise, fast, feature-rich
Stars: ✭ 141 (-21.23%)
Mutual labels:  wpf, xamarin-forms, maui
Uno
Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported.
Stars: ✭ 6,029 (+3268.16%)
Mutual labels:  xaml, uno-platform, winui
Arcgis Toolkit Dotnet
Toolkit for ArcGIS Runtime SDK for .NET
Stars: ✭ 125 (-30.17%)
Mutual labels:  xaml, wpf, xamarin-forms
Modernwpf
Modern styles and controls for your WPF applications
Stars: ✭ 2,610 (+1358.1%)
Mutual labels:  xaml, wpf, winui
WinDev-Utility
A utility for windows developers
Stars: ✭ 17 (-90.5%)
Mutual labels:  wpf, uno-platform
MADE.NET
MADE.NET is a home to all of those bits of code that you know you'll reuse in another project. Making app development easier with .NET.
Stars: ✭ 75 (-58.1%)
Mutual labels:  maui, uno-platform
SimpleDialogs
💬 A simple framework to help displaying dialogs on a WPF app
Stars: ✭ 24 (-86.59%)
Mutual labels:  xaml, wpf
Taskban
A personal productivity tool developed with C# and XAML.
Stars: ✭ 56 (-68.72%)
Mutual labels:  xaml, wpf
net6.0-mobile-fsharp
Mobile templates for .NET 7.0 / F# 7.0
Stars: ✭ 76 (-57.54%)
Mutual labels:  xamarin-forms, maui

MvvmGen

Build MvvmGen NuGet MvvmGen NuGet MvvmGen

Your Friend Who Writes the Boilerplate for You

Hey there, welcome to the MvvmGen repository. MvvmGen is a lightweight and modern MVVM library (.NET Standard 2.0) built with C# Source Generators that helps you to apply the popular Model-View-ViewModel-pattern (MVVM) in your XAML applications that you build with WPF, WinUI, Uno Platform, Avalonia, Xamarin Forms, or .NET MAUI.

MvvmGen is licensed under the MIT license.

Get Started

Quick intro

In this quick intro, you'll learn that creating a ViewModel is a lot of fun with MvvmGen! 🔥

Installing the MvvmGen NuGet Package

Reference the NuGet package MvvmGen in your .NET application, and then you're ready to go:

Install-Package MvvmGen

MvvmGen will register itself as a C# source generator in your project, and it will be your friend who writes the boilerplate for you.

Generating a ViewModel class

To generate a ViewModel class, you create a new class, you mark it as partial, and you put MvvmGen's ViewModel attribute on the class:

using MvvmGen;

namespace MyWpfApp.ViewModel
{
  [ViewModel]
  public partial class EmployeeViewModel
  {
  }
}

The ViewModel attribute tells MvvmGen to generate another partial EmployeeViewModel class. Right now, it will be a class that looks like this:

using MvvmGen.Commands;
using MvvmGen.Events;
using MvvmGen.ViewModels;

namespace MyWpfApp.ViewModel
{
    partial class EmployeeViewModel : ViewModelBase
    {
        public EmployeeViewModel()
        {
            this.OnInitialize();
        }

        partial void OnInitialize();
    }
}

You can see that generated class in Visual Studio under Dependencies->Analyzers: Generated class

Beside the ViewModel attribute, you find many other attributes in the MvvmGen namespace that you can use to decorate your ViewModel class. These attributes allow you to build a full ViewModel like this:

using MvvmGen;
using MvvmGen.Events;

namespace MyWpfApp
{
  public record EmployeeSavedEvent(string FirstName, string LastName);

  [Inject(typeof(IEventAggregator))]
  [ViewModel]
  public partial class EmployeeViewModel
  {
    [Property] private string _firstName;
    [Property] private string _lastName;

    [Command(CanExecuteMethod = nameof(CanSave))]
    private void Save()
    {
      EventAggregator.Publish(new EmployeeSavedEvent(FirstName, LastName));
    }

    [CommandInvalidate(nameof(FirstName))]
    private bool CanSave()
    {
      return !string.IsNullOrEmpty(FirstName);
    }
  }
}

For this ViewModel, MvvmGen will generate the following partial class definition for you

using MvvmGen.Commands;
using MvvmGen.Events;
using MvvmGen.ViewModels;

namespace MyWpfApp
{
  partial class EmployeeViewModel : ViewModelBase
  {
    public EmployeeViewModel(MvvmGen.Events.IEventAggregator eventAggregator)
    {
      this.EventAggregator = eventAggregator;
      this.InitializeCommands();
      this.OnInitialize();
    }

    partial void OnInitialize();

    private void InitializeCommands()
    {
      SaveCommand = new DelegateCommand(_ => Save(), _ => CanSave());
    }

    public DelegateCommand SaveCommand { get; private set; }

    public string FirstName
    {
      get => _firstName;
      set
      {
        if (_firstName != value)
        {
          _firstName = value;
          OnPropertyChanged("FirstName");
        }
      }
    }

    public string LastName
    {
      get => _lastName;
      set
      {
        if (_lastName != value)
        {
          _lastName = value;
          OnPropertyChanged("LastName");
        }
      }
    }

    protected MvvmGen.Events.IEventAggregator EventAggregator { get; private set; }
    
    protected override void InvalidateCommands(string? propertyName)
    {
      base.InvalidateCommands(propertyName);
      if(propertyName == "FirstName")
      {
          SaveCommand.RaiseCanExecuteChanged();
      }
    }
  }
}

To learn all the details, go to the documentation in this repo.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].