Skip to content

Latest commit

 

History

History
117 lines (88 loc) · 4.57 KB

File metadata and controls

117 lines (88 loc) · 4.57 KB

MvvmScarletToolkit.Observables

.NET standard 2.0

Goals

This library aims to provide base and utility classes around state and state management in viewmodels in the MVVM pattern.

Contents

class summary
ObservableCircularBuffer<T> Wraps a fixed sized ObservableCollection<T> and removes the last entry when a new entry is added in the beginning of the collection

ViewModels

class summary
ObservableObject General purpose implementation of the INotifyPropertyChanged interface
ViewModeBase BaseViewModel that serves as service aggregate and caches INotifyPropertyChanged EventArgs
ViewModeBase<T> Generic version of the ViewModelBase exposing an injected (model)class
ViewModeListBase<T> Base class that provides a common set of actions for a collection entity viewmodel centered around loading and unlad state and/or data.
ViewModelContainer<T> Generic wrapper viewmodel to add binding support
BusinessViewModelBase ViewModelBase that bootstraps loading, unloading and refreshing of its content
BusinessViewModelBase<T> Generic ViewModelBase that bootstraps loading, unloading and refreshing of its content
BusinessViewModelListBase<T> Collection ViewModelBase that bootstraps loading, unloading and refreshing of its content
PagingViewModel ViewModel that adds paging support to DomainViewModelListBase<TViewModel>

Usage

ObservableObject
using MvvmScarletToolkit.Observables;

// DerivedObservableObject.cs
internal sealed class DerivedObservableObject : ObservableObject
{
    private object _notifyingProperty;
    public object NotifyingProperty
    {
        get { return _notifyingProperty; }
        set { SetValue(ref _notifyingProperty, value, onChanged: OnChanged, onChanging: OnChanging); }
    }

    private void OnChanged()
    {
        // your code here, when NotifyingProperty changed
    }

    private void OnChanging()
    {
        // your code here, when NotifyingProperty is about to change
    }
}
ViewModelBase
using MvvmScarletToolkit.Observables;

// DerivedViewModelBase.cs
internal sealed class DerivedViewModelBase : ViewModelBase
{
    public DerivedViewModelBase(IScarletCommandBuilder commandBuilder)
        : base(commandBuilder)
    {
    }
}
ViewModelBase<TClass>
using MvvmScarletToolkit.Observables;

// TClass is equivalent to any class
// DerivedObjectViewModelBase.cs
internal sealed class DerivedObjectViewModelBase : ViewModelBase<TClass>
{
    public DerivedObjectViewModelBase(IScarletCommandBuilder commandBuilder, TClass model)
        : base(commandBuilder)
    {
    }
}

State

class summary
BusyStack Threadsafe class that executes an action, providing information whether it currently contains any BusyToken when the Pull or Push methods are being called.
ObservableBusyStack Threadsafe class that executes an action, providing information whether it currently contains any BusyToken when the Pull or Push methods are being called. Additionally provides means for observing other classes and being observed according to the IObserver<T> and IObservable<T> interfaces.
BusyToken A a disposable class thats being used by the IBusyStack implementations of this library

Navigation

class summary
Scene Simple viewmodel class that provides a viewmodel property and whether it is selected
Scenes Abstract viewmodel collection class that holds instances of Scenes. Usecase is for having a starting point to writing your own navigation system.

Localization

class summary
LocalizationViewModel Provides binding support for a localized string
LocalizationsViewModel Viewmodel providing binding support for current language and support languages of a given ILocalizationProvider