Capoala.MVVM 2019.0.1

Additional Details

This project is no longer actively maintained.

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

// Install Capoala.MVVM as a Cake Tool
#tool nuget:?package=Capoala.MVVM&version=2019.0.1

Capoala.MVVM

Capoala.MVVMis a minimalist framework for MVVM based applications. This framework provides both IPropertyChanged and ICommand implementations, as well as a simple navigation base.

ICommand

CommandRelay

The CommandRelay implements the ICommand interface and comes in two flavors; CommandRelay and CommandRelay<TExecutionParameter> for passing a parameter to the execute method.

Class ViewModel
using Capoala.MVVM;
using System.Diagnostics;

internal class ViewModel
{
    public CommandRelay SaveCommand { get; } 
        = new CommandRelay(() => Debug.WriteLine("Saving..."));

    public CommandRelay<string> AddInputCommand { get; } 
        = new CommandRelay<string>(input => Debug.WriteLine(input));
}
XAML
  • NuGet 8000 byte limit

INotifyPropertyChanged

INotifyPropertyChanges

The INotifyPropertyChanges is a custom interface for implementing the INotifyPropertyChanged interface. The INotifyPropertyChanges interface exposes methods for implementing the INotifyPropertyChanged event and is defined - without summaries - as follows:

public interface INotifyPropertyChanges : INotifyPropertyChanged
{
    void Notify([CallerMemberName] string propertyName = null);

    bool SetAndNotify<T>(
        ref T backingField, 
        T value, 
        EqualityComparer<T> equalityComparer = null, 
        [CallerMemberName] string propertyName = null);
}

NotifyPropertyChangesBaseSlim

NotifyPropertyChangesBaseSlim is an abstract class that simply implements the INotifyPropertyChanges interface.

NotifyPropertyChangesBase

NotifyPropertyChangesBase is an abstract class that implements the INotifyPropertyChanges interface and supports the SubscribeToChanges, NotifyOnChange, and CanExecuteDependentOn attributes. These attributes allow a streamlined approach to notifying other properties and re-triggering the NotifyCanExecuteDidChange method on CommandRelay objects.

using Capoala.MVVM;
using System.Windows;

internal class SampleViewModel : NotifyPropertyChangesBase
{
    private bool _isOperationInProgress = false;
    public bool IsOperationInProgress 
    { 
        get => _isOperationInProgress; 
        set => SetAndNotify(ref _isOperationInProgress, value); 
    }

    private string _firstName;
    public string FirstName 
    { 
        get => _firstName; 
        set => SetAndNotify(ref _firstName, value); 
    }

    private string _lastName;
    public string LastName 
    { 
        get => _lastName; 
        set => SetAndNotify(ref _lastName, value); 
    }

    [SubscribeToChanges(nameof(FirstName), nameof(LastName))]
    public string DisplayName => $"{FirstName} {LastName}";

    [CanExecuteDependentOn(nameof(FirstName), nameof(LastName), nameof(IsOperationInProgress))]
    public CommandRelay CreateCommand { get; }

    public SampleViewModel() => CreateCommand = new CommandRelay(() => 
    {
        // Do Something.

    }, () => !IsOperationInProgress && 
             !string.IsNullOrEmpty(FirstName) && 
             !string.IsNullOrEmpty(LastName))
}

NotifyPropertyChangesBaseAutoBackingStore

NotifyPropertyChangesBaseAutoBackingStore is an abstract class that inherits from NotifyPropertyChangesBase, but includes a "backing store" in the form of a Dictionary<string, object>. This allows us to not have to define private fields and is useful for testing and "notifying" models. Using the above sample, below is how the code would look using the NotifyPropertyChangesBaseAutoBackingStore base class.

using Capoala.MVVM;
using System.Windows;

internal class SampleViewModel : NotifyPropertyChangesBaseAutoBackingStore
{
    public bool IsOperationInProgress { get => Get<bool>(); set => Set(value); 
    public string FirstName { get => Get<string>(); set => Set(value); 
    public string LastName { get => Get<string>(); set => Set(value); 

    [SubscribeToChanges(nameof(FirstName), nameof(LastName))]
    public string DisplayName => $"{FirstName} {LastName}";

    [CanExecuteDependentOn(nameof(FirstName), nameof(LastName), nameof(IsOperationInProgress))]
    public CommandRelay CreateCommand { get; }

    public SampleViewModel() => CreateCommand = new CommandRelay(() => 
    {
        // Do Something.

    }, () => !IsOperationInProgress && 
             !string.IsNullOrEmpty(FirstName) && 
             !string.IsNullOrEmpty(LastName))    
}

SimpleMvvmNavigator<TNavigationItem>

The SimpleMvvmNavigator<TNavigationItem> class is a simplistic implementation for navigation. This class exposes only an event for subscribing to navigation changes and a method for performing the navigation itself.

internal static class Services
{
    internal static SimpleMvvmNavigator<INotifyPropertyChanges> Navigator { get; } 
        = new SimpleMvvmNavigator<INotifyPropertyChanges>();
}

internal class MainViewModel : NotifyPropertyChangesBaseAutoBackingStore
{
    public INotifyPropertyChanges CurrentViewModel 
    { 
        get => Get<INotifyPropertyChanges>(); 
        set => Set(value); 
    }

    public MainViewModel() => 
        Services.Navigator.NavigationDidHappen += (s, e) => 
            CurrentViewModel = e.NavigationItem;
}

internal class TestViewModel : INotifyPropertyChanges
{
    public CommandRelay<INotifyPropertyChanges> Navigate { get; } 
        = new CommandRelay<INotifyPropertyChanges>(
            (viewModel) => Services.Navigator.NavigateTo(viewModel));
}

MvvmNavigatorBase<TNavigationItem>

MvvmNavigatorBase<TNavigationItem> is an abstract class for implementing a more robust, full featured navigation scheme. This class has default support for going both back and forward as well as additional properties to allow for modification on class inheritance.

MvvmNavigator

MvvmNavigator is a default implementation of MvvmNavigatorBase and allows constructor settings for supporting back and forward navigation, which can yield a small performance benefit.

internal static class Services
{
    internal static MvvmNavigator<INotifyPropertyChanges> Navigator { get; } 
        = new MvvmNavigator<INotifyPropertyChanges>();

    internal static MvvmNavigator<INotifyPropertyChanges> NoForwardNavigator { get; } 
        = new MvvmNavigator<INotifyPropertyChanges>(supportsForwardNavigation: false);

    internal static MvvmNavigator<INotifyPropertyChanges> NoBackNavigator { get; } 
        = new MvvmNavigator<INotifyPropertyChanges>(supportsBackNavigation: false);

    /* NuGet 8000 byte limit */
}

Attributes

SubscribeToChanges

SubscribeToChanges is an attribute used to allow a property with this attribute to subscribe to value changes of other properties.

NotifyOnChange

NotifyOnChange is an attribute used to allow a property with this attribute to notify other properties when its value changes.

CanExecuteDependentOn

CanExecuteDependentOn is an attribute used to allow a property - of type CommandRelay or CommandRelay<TExecutionParameter> - to subscribe to value changes of other properties. This attribute differs from SubscribeToChanges, as SubscribeToChanges will raise the PropertyChangedEventHandler event of an INotifyPropertyChanged interface, while this attribute will raise the CanExecuteChanged event of an ICommand interface.

Events and Event Arguments

NavigationChangedEventHandler<TNavigationItem> is a delegate for supporting navigation changes.

The NavigationChangedEventArgs<TNavigationItem> class is used with the NavigationChangedEventHandler<TNavigationItem> event handler for navigation support.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 is compatible.  netcoreapp2.2 is compatible.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 is compatible.  net471 is compatible.  net472 is compatible.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 2.1

    • No dependencies.
  • .NETCoreApp 2.2

    • No dependencies.
  • .NETFramework 4.7

    • No dependencies.
  • .NETFramework 4.7.1

    • No dependencies.
  • .NETFramework 4.7.2

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.

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
2019.0.1 739 3/7/2019
2019.0.0-beta.3 331 3/3/2019
2019.0.0-alpha.4 326 3/2/2019
2019.0.0-alpha.3 309 3/1/2019
2019.0.0-alpha.2 303 2/28/2019
2019.0.0-alpha.1 302 2/27/2019
2017.1.2.5 1,052 11/28/2017
2017.1.1.3 1,382 11/19/2017

Release Notes 2019

API Breaking Changes

This release is incompatible with prior 2017.x releases. Breaking API changes were made due to a combination
of naming conflicts, undesirable - or lack of - functionality, and scalability.


- RelayCommand and RelayCommand<TParameter> have been renamed to CommandRelay and CommandRelay<TExecutionParameter> respectively.
- CommandRelay<TExecutionParameter> no longer supports parameter passing to the CanExecutePredicate function.
- NotifiedOnChange has been renamed to SubscribeToChanges.
- NotifiesOnChange has been renamed to NotifyOnChange.
- A new attribute, CanExecuteDependentOn, now allows for a CommandRelay property to subscribe to property changes that will invoke the CommandRelay's NotifyCanExecuteDidChange() method.
- New INotifyPropertyChanges interface for providing a common object for INotifyPropertyChanged implementations.
- NotifyingObjectBaseSlim has been renamed to NotifyPropertyChangesBaseSlim and implements the INotifyPropertyChanges interface.
- NotifyingObjectBase has been renamed to NotifyPropertyChangesBase and implements the INotifyPropertyChanges interface.
- NotifyPropertyChangesBase supports the NotifyOnChange, SubscribeToChanges, and CanExecuteDependentOn attributes.
- The "auto backing store" functionality has been moved into a new class named NotifyPropertyChangesBaseAutoBackingStore.
- The INavigationService<TNavigationItem> has been dropped.
- The NavigationServiceBase<TNavigationItem> has been revamped and renamed to MvvmNavigatorBase<TNavigationItem>.
- DefaultNavigationService has been renamed to MvvmNavigator<TNavigationItem> and inherits from MvvmNavigatorBase<TNavigationItem>.
- SimpleMvvmNavigator is a simplified implementation of MvvmNavigatorBase, but does not inherit from MvvmNavigatorBase.
- The navigation service implementations now utilize a custom event handler NavigationChangedEventHandler with event argument NavigationChangedEventArgs.