https://github.com/bushero/nanomvvm
An unobtrusive MVVM Library
https://github.com/bushero/nanomvvm
mvvm
Last synced: over 1 year ago
JSON representation
An unobtrusive MVVM Library
- Host: GitHub
- URL: https://github.com/bushero/nanomvvm
- Owner: BusHero
- License: mit
- Created: 2021-12-18T04:31:52.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-12-21T17:13:06.000Z (over 4 years ago)
- Last Synced: 2025-01-29T21:54:52.832Z (over 1 year ago)
- Topics: mvvm
- Language: C#
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# NanoMVVM
A small collection of stuff I use across WPF projects.
## ViewModelBase/ViewModelBase
The base class for all view models.
Use the generic version.
Implements
Usage example:
```c#
public class MyViewModel : ViewModelBase
{
private int foo;
public int Foo { get => foo; set => Set(ref foo, value); }
public MyViewModel
{
SubscribePropertyChanged(nameof(Foo), () => { /* Do something */ });
SubscribePropertyChanged(nameof(Foo), (MyViewModel myViewModel) => { /* Do something */});
SubscribePropertyChanged(nameof(Foo), HandleFooChanged);
SubscribePropertyChanged(nameof(Foo), HandleFooChangedWithArgument);
}
private void HandleFooChanged()
{
// Do something
}
private void HandleFooChangedWithArgument(MyViewModel myViewModel)
{
// Do something
}
}
```
## Commands
Package provide utility methods to create custom commands through the Commands utility class.
The method through which a command is created is CreateCommand(...).
It has a number of overrides to create command in a variaty of scenarios.
Examples:
```c#
ICommand command = Commands.CreateCommand(() => { /* Do something ignoring the argument */});
ICommand commandWithObjectArgument = Commands.CreateCommand((object arg) => { /* Do something */});
ICommand commandWithStronglyTypedArgument = Commands.CreateCommand((T arg) => { /* Do something */});
```