Unosquare
    Show / Hide Table of Contents

    Class ViewModelBase

    A base class for implementing models that fire notifications when their properties change. This class is ideal for implementing MVVM driven UIs.

    Inheritance
    Object
    ViewModelBase
    Namespace: Swan
    Syntax
    public abstract class ViewModelBase : INotifyPropertyChanged

    Constructors

    ViewModelBase()

    Initializes a new instance of the ViewModelBase class.

    Declaration
    protected ViewModelBase()

    ViewModelBase(Boolean)

    Initializes a new instance of the ViewModelBase class.

    Declaration
    protected ViewModelBase(bool useDeferredNotifications)
    Parameters
    Type Name Description
    Boolean useDeferredNotifications

    Set to true to use deferred notifications in the background.

    Methods

    NotifyPropertyChanged(String[])

    Notifies one or more properties changed.

    Declaration
    protected void NotifyPropertyChanged(params string[] propertyNames)
    Parameters
    Type Name Description
    String[] propertyNames

    The property names.

    SetProperty<T>(ref T, T, String, String[])

    Checks if a property already matches a desired value. Sets the property and notifies listeners only when necessary.

    Declaration
    protected bool SetProperty<T>(ref T storage, T value, string propertyName = "", string[] notifyAlso = null)
    Parameters
    Type Name Description
    T storage

    Reference to a property with both getter and setter.

    T value

    Desired value for the property.

    String propertyName

    Name of the property used to notify listeners. This value is optional and can be provided automatically when invoked from compilers that support CallerMemberName.

    String[] notifyAlso

    An array of property names to notify in addition to notifying the changes on the current property name.

    Returns
    Type Description
    Boolean

    True if the value was changed, false if the existing value matched the desired value.

    Type Parameters
    Name Description
    T

    Type of the property.

    Events

    PropertyChanged

    Declaration
    public event PropertyChangedEventHandler PropertyChanged
    Event Type
    Type Description
    PropertyChangedEventHandler

    Comments

    Back to top Copyright © 2017-2019 Unosquare