Capoala.MVVM 2019.0.1

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

Install-Package Capoala.MVVM -Version 2019.0.1
dotnet add package Capoala.MVVM --version 2019.0.1
<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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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&lt;TExecutionParameter&gt; 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&lt;string, object&gt;. 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))    
}

Navigation

SimpleMvvmNavigator<TNavigationItem>

The SimpleMvvmNavigator&lt;TNavigationItem&gt; 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&lt;TNavigationItem&gt; 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&lt;TExecutionParameter&gt; - 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>

NavigationChangedEventHandler&lt;TNavigationItem&gt; is a delegate for supporting navigation changes.

NavigationChangedEventArgs<TNavigationItem>

The NavigationChangedEventArgs&lt;TNavigationItem&gt; class is used with the NavigationChangedEventHandler&lt;TNavigationItem&gt; event handler for navigation support.

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&lt;TExecutionParameter&gt; 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&lt;string, object&gt;. 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))    
}

Navigation

SimpleMvvmNavigator<TNavigationItem>

The SimpleMvvmNavigator&lt;TNavigationItem&gt; 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&lt;TNavigationItem&gt; 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&lt;TExecutionParameter&gt; - 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>

NavigationChangedEventHandler&lt;TNavigationItem&gt; is a delegate for supporting navigation changes.

NavigationChangedEventArgs<TNavigationItem>

The NavigationChangedEventArgs&lt;TNavigationItem&gt; class is used with the NavigationChangedEventHandler&lt;TNavigationItem&gt; event handler for navigation support.

Release Notes

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.

  • .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.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2019.0.1 146 3/7/2019
2019.0.0-beta.3 88 3/3/2019
2019.0.0-alpha.4 72 3/2/2019
2019.0.0-alpha.3 71 3/1/2019
2019.0.0-alpha.2 73 2/28/2019
2019.0.0-alpha.1 69 2/27/2019
2017.1.2.5 402 11/28/2017
2017.1.1.3 658 11/19/2017