Capoala.MVVM 2017.1.2.5

A featherweight MVVM framework designed for simple-to-moderate MVVM design pattern applications. This framework includes basic implementations for handling property notifications, command bindings, and navigation.

There is a newer version of this package available.
See the version list below for details.
Install-Package Capoala.MVVM -Version 2017.1.2.5
dotnet add package Capoala.MVVM --version 2017.1.2.5
<PackageReference Include="Capoala.MVVM" Version="2017.1.2.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Capoala.MVVM --version 2017.1.2.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Capoala.MVVM

Capoala.MVVM is a featherlight MVVM framework designed for simple-to-moderate MVVM design pattern applications. This framework includes basic implementations for handling property notifications, command bindings, and navigation.

INotifyPropertyChanged

NotifyingObjectBaseSlim

The NotifyingObjectBaseSlim class is a slim, standard INotifyPropertyChanged implementation. A streamlined method named SetAndNotify() will set the referenced property's value and raise the PropertyChanged event in one swell swoop.

public class ViewModel : Capoala.MVVM.NotifyingObjectBaseSlim
{
    string _name = null;
    public string Name { get => _name; set => SetAndNotify(ref _name, value); }
}

In cases where extra work or additional notifications are required, you can use standard getter setter syntax and utilize the Notify() method to raise the PropertyChanged event on the property being set.

public class ViewModel : Capoala.MVVM.NotifyingObjectBaseSlim
{
    string _firstName = null;
    public string FirstName
    {
        get => _firstName;
        set
        {
            _firstName = value;
            Notify();
            Notify(nameof(FullName));
        }
    }

    string _lastName = null;
    public string LastName
    {
        get => _lastName;
        set
        {
            if (SetAndNotify(ref _lastName, value))
                Notify(nameof(FullName));
        }
    }

    public string FullName => $"{FirstName} {LastName}";
}

NotifyingObjectBase

The NotifyingObjectBase class is a more feature-rich implementation of the INotifyPropertyChanged interface. This class removes the requirement of a backing field and moves it into a backing store in the form of a Dictionary&lt;string, object&gt;.

This class also provides an attribute approach to streamlining property notification dependencies. In the below example, the property FullName subscribes to the FirstName and LastName event changes. When either FirstName or LastName is changed, FullName is also notified.

public class ViewModel : Capoala.MVVM.NotifyingObjectBase
{
    public string FirstName { get => Get<string>(); set => Set(value); }
    public string LastName { get => Get<string>(); set => Set(value); }

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

ICommand

RelayCommand

The RelayCommand implements the ICommand interface and comes in two flavors; RelayCommand and RelayCommand&lt;T&gt; for passing command paramters.

using Capoala.MVVM;
using DW = System.Diagnostics.Debug;

public class ViewModel
{
    public RelayCommand SaveCommand { get; } 
        = new RelayCommand(() => DW.WriteLine("Saving..."));

    public RelayCommand<string> GetRecordCommand { get; } 
        = new RelayCommand<string>(entryName => DW.WriteLine(entryName));
}
...
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>
    <TextBox x:Name="RecordID"/>
    <Button Grid.Column="1" 
            Margin="10 0 0 0" 
            Command="{Binding GetRecordCommand}" 
            CommandParameter="{Binding ElementName=RecordID, Path=Text}">Retreive</Button>
</Grid>
<Grid Grid.Row="1" Margin="0 20 0 0">
    <!--Content-->
</Grid>
<Grid Grid.Row="2" Margin="0 20 0 0">
    <Button HorizontalAlignment="Right" 
            Command="{Binding SaveCommand}">Save</Button>
</Grid>
...

Navigation

A simplistic navigation implementation is also available which should satisfy most requirements. The navigation system includes an INavigationService&lt;TNavigationItem&gt; interface, and a NavigationServiceBase&lt;TNavigationItem&gt; base class.

using Capoala.MVVM;

public static class NavigationHelper
{
    public static INavigationService<object> Navigator { get; } 
        = new DefaultNavigationService();
}

public class ViewModel { }

public class MainViewModel : NotifyingObjectBase
{
    public object CurrentViewModel { get => Get<object>(); set => Set(value); }

    public MainViewModel()
    {
        NavigationHelper.Navigator.NavigationDidHappen += (s, e) =>
        {
            CurrentViewModel = NavigationHelper.Navigator.Current;
        };

        NavigationHelper.Navigator.Navigate(new ViewModel());
    }
}

Capoala.MVVM

Capoala.MVVM is a featherlight MVVM framework designed for simple-to-moderate MVVM design pattern applications. This framework includes basic implementations for handling property notifications, command bindings, and navigation.

INotifyPropertyChanged

NotifyingObjectBaseSlim

The NotifyingObjectBaseSlim class is a slim, standard INotifyPropertyChanged implementation. A streamlined method named SetAndNotify() will set the referenced property's value and raise the PropertyChanged event in one swell swoop.

public class ViewModel : Capoala.MVVM.NotifyingObjectBaseSlim
{
    string _name = null;
    public string Name { get => _name; set => SetAndNotify(ref _name, value); }
}

In cases where extra work or additional notifications are required, you can use standard getter setter syntax and utilize the Notify() method to raise the PropertyChanged event on the property being set.

public class ViewModel : Capoala.MVVM.NotifyingObjectBaseSlim
{
    string _firstName = null;
    public string FirstName
    {
        get => _firstName;
        set
        {
            _firstName = value;
            Notify();
            Notify(nameof(FullName));
        }
    }

    string _lastName = null;
    public string LastName
    {
        get => _lastName;
        set
        {
            if (SetAndNotify(ref _lastName, value))
                Notify(nameof(FullName));
        }
    }

    public string FullName => $"{FirstName} {LastName}";
}

NotifyingObjectBase

The NotifyingObjectBase class is a more feature-rich implementation of the INotifyPropertyChanged interface. This class removes the requirement of a backing field and moves it into a backing store in the form of a Dictionary&lt;string, object&gt;.

This class also provides an attribute approach to streamlining property notification dependencies. In the below example, the property FullName subscribes to the FirstName and LastName event changes. When either FirstName or LastName is changed, FullName is also notified.

public class ViewModel : Capoala.MVVM.NotifyingObjectBase
{
    public string FirstName { get => Get<string>(); set => Set(value); }
    public string LastName { get => Get<string>(); set => Set(value); }

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

ICommand

RelayCommand

The RelayCommand implements the ICommand interface and comes in two flavors; RelayCommand and RelayCommand&lt;T&gt; for passing command paramters.

using Capoala.MVVM;
using DW = System.Diagnostics.Debug;

public class ViewModel
{
    public RelayCommand SaveCommand { get; } 
        = new RelayCommand(() => DW.WriteLine("Saving..."));

    public RelayCommand<string> GetRecordCommand { get; } 
        = new RelayCommand<string>(entryName => DW.WriteLine(entryName));
}
...
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>
    <TextBox x:Name="RecordID"/>
    <Button Grid.Column="1" 
            Margin="10 0 0 0" 
            Command="{Binding GetRecordCommand}" 
            CommandParameter="{Binding ElementName=RecordID, Path=Text}">Retreive</Button>
</Grid>
<Grid Grid.Row="1" Margin="0 20 0 0">
    <!--Content-->
</Grid>
<Grid Grid.Row="2" Margin="0 20 0 0">
    <Button HorizontalAlignment="Right" 
            Command="{Binding SaveCommand}">Save</Button>
</Grid>
...

Navigation

A simplistic navigation implementation is also available which should satisfy most requirements. The navigation system includes an INavigationService&lt;TNavigationItem&gt; interface, and a NavigationServiceBase&lt;TNavigationItem&gt; base class.

using Capoala.MVVM;

public static class NavigationHelper
{
    public static INavigationService<object> Navigator { get; } 
        = new DefaultNavigationService();
}

public class ViewModel { }

public class MainViewModel : NotifyingObjectBase
{
    public object CurrentViewModel { get => Get<object>(); set => Set(value); }

    public MainViewModel()
    {
        NavigationHelper.Navigator.NavigationDidHappen += (s, e) =>
        {
            CurrentViewModel = NavigationHelper.Navigator.Current;
        };

        NavigationHelper.Navigator.Navigate(new ViewModel());
    }
}

Release Notes

Release Notes 2017.1.2.5
The Set() and SetAndNotify() methods now return a boolean value for evaluating whether the property was set or not.
The Set() and SetAndNotify() methods now allow for a different equality comparer to be used.

Release Notes 2017.1.1.3
Provides default implementations of the INotifyPropertyChanged interface.
Provides default implementations of the ICommand interface.
Provides default implementations of a navigation service.

  • .NETFramework 4.6.2

    • No dependencies.
  • .NETFramework 4.7

    • 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 158 3/7/2019
2019.0.0-beta.3 89 3/3/2019
2019.0.0-alpha.4 73 3/2/2019
2019.0.0-alpha.3 72 3/1/2019
2019.0.0-alpha.2 74 2/28/2019
2019.0.0-alpha.1 70 2/27/2019
2017.1.2.5 406 11/28/2017
2017.1.1.3 719 11/19/2017
Show less