Append.Mvvm
2018.1.0.21
dotnet add package Append.Mvvm --version 2018.1.0.21
NuGet\Install-Package Append.Mvvm -Version 2018.1.0.21
<PackageReference Include="Append.Mvvm" Version="2018.1.0.21" />
paket add Append.Mvvm --version 2018.1.0.21
#r "nuget: Append.Mvvm, 2018.1.0.21"
// Install Append.Mvvm as a Cake Addin
#addin nuget:?package=Append.Mvvm&version=2018.1.0.21
// Install Append.Mvvm as a Cake Tool
#tool nuget:?package=Append.Mvvm&version=2018.1.0.21
Append MVVM Framework
This project is a simple MVVM framework in C#, using .NET standard 2.0. It is designed to be used with WPF, UWP and Xamarin Forms.
Important
Use this framework at your own risk!
Copyright
This library and all code are copyrighted the author Stian Skreosen Mandelid.
License
The MIT License (MIT)
Copyright (c) 2018 Stian Skreosen Mandelid
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.
Future plans
- Make the framework thread safe.
- Profile for memory leaks.
Contacts ViewModel example
Just to give a quick overview of how a ViewModel looks like in this framework, an example is provided beneath. More documentation is available after this example.
using Append.Mvvm.Interfaces;
namespace MyNamespace
{
public class ContactsViewModel : ViewModelBase
{
private IMvvmProperty<string> _NameToAdd;
private IMvvmListProperty<string> _Contacts;
private IMvvmComputed<string> _NumberOfNames;
public ContactsViewModel()
{
_NameToAdd = MvvmProperty<string>(nameof(NameToAdd));
_Contacts = MvvmList<string>(nameof(Contacts));
_NumberOfNames = MvvmComputed(
nameof(NumberOfNames),
() => $"Number of contacts: {Contacts.Count}");
AddContactCommand = MvvmCommand(
nameof(AddContactCommand),
() => AddContactCommandActinn(),
() => !string.IsNullOrWhiteSpace(NameToAdd));
}
public string NameToAdd
{
get { return _NameToAdd.Value; }
set { _NameToAdd.Value = value; }
}
public IMvvmList<string> Contacts => _Contacts.Value;
public string NumberOfNames => _NumberOfNames.Value;
public IMvvmCommand AddContactCommand { get; }
private void AddContactCommandActinn()
{
Contacts.Add(NameToAdd);
NameToAdd = null;
}
}
}
Documentation
Important note
The order of these declarations is important. A MvvmComputed
cannot be declared before a MvvmProperty
that it calculated within it. The best practice is to declare in this order:
MvvmProperty
andMvvmList
MvvmComputed
MvvmCommand
The ViewModelBase
class
To use this framework you create a ViewModel class that inherits from the ViewModelBase
class.
Example
public class MyViewModel : ViewModelBase
{
// More code here
}
Example with isInDesignerMode
The purpose of the isInDesignerMode
parameter is to prevent the mechanisms in the framework to be executed. In a WPF/UWP project, it can be used to prevent SQL queries or other unwanted code to execution in design time.
public class MyViewModel : ViewModelBase
public MyViewModel()
: base(Application.IsRunning) { }
}
The ViewModelBase
methods
MvvmProperty
Example
_NameToAdd = MvvmProperty<string>(nameof(NameToAdd));
Description
Implements INotifyPropertyChanged
that can be databound in a view, and notifies the view when the property value changes.
MvvmList
Example
_Contacts = MvvmList<string>(nameof(Contacts));
Description
Implements INotifyCollectionChanged
and INotifyPropertyChanged
that can be databound in a view, and notifies the view when the collection changes.
The view will also be notified if the collection contains MvvmProperty
objects or objects that implement INotifyPropertyChanged
, and any of these objects notifies that a property value has changed. This can be disabled by setting the notifyItemsValueChange
parameter to false.
MvvmComputed
Example
_NumberOfNames = MvvmComputed(
nameof(NumberOfNames),
() => $"Number of contacts: {Contacts.Count}");
Description
A calculated property that will invoke the computedFunction
on declaration and every time a MvvmProperty
, MvvmList
or MvvmComputed
value changes that are used in it.
MvvmCommand
Example
// Command without a command parameter
AddContactCommand = MvvmCommand(
nameof(AddContactCommand),
() => AddContactCommandActinn(),
() => !string.IsNullOrWhiteSpace(NameToAdd));
// Command with a command parameter
AddContactCommand = MvvmCommand<string>(
nameof(AddContactCommand),
contactName => AddContactCommandActinn(contactName),
contactName => !string.IsNullOrWhiteSpace(contactName));
Description
A command property that implements System.Windows.Input.ICommand
that can be bound to a component that supports command in the view.
When MvvmProperty
or MvvmComputed
objects are used in the canExecuteFunction
parameter and any of the object value changes, the expression will be invoked to determine if the command can be executed.
Product | Versions 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 was computed. netcoreapp2.2 was computed. 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 was computed. net471 was computed. net472 was computed. 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. |
This package has 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 |
---|