docs.unity3d.com
    Show / Hide Table of Contents

    Class ObservableObject

    A base class for objects of which the properties must be observable.

    Inheritance
    Object
    ObservableObject
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unity.AppUI.MVVM
    Syntax
    public abstract class ObservableObject : INotifyPropertyChanged, INotifyPropertyChanging

    Methods

    OnPropertyChanged(PropertyChangedEventArgs)

    Raises the PropertyChanged event.

    Declaration
    protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
    Parameters
    Type Name Description
    PropertyChangedEventArgs e

    The event data.

    Exceptions
    Type Condition
    ArgumentNullException

    e is null.

    OnPropertyChanged(String)

    Raises the PropertyChanged event.

    Declaration
    protected void OnPropertyChanged(string propertyName = null)
    Parameters
    Type Name Description
    String propertyName

    The name of the property that has changed.

    OnPropertyChanging(PropertyChangingEventArgs)

    Raises the PropertyChanging event.

    Declaration
    protected virtual void OnPropertyChanging(PropertyChangingEventArgs e)
    Parameters
    Type Name Description
    PropertyChangingEventArgs e

    The event data.

    Exceptions
    Type Condition
    ArgumentNullException

    e is null.

    OnPropertyChanging(String)

    Raises the PropertyChanging event.

    Declaration
    protected void OnPropertyChanging(string propertyName = null)
    Parameters
    Type Name Description
    String propertyName

    The name of the property that is changing.

    SetProperty<T>(T, T, Action<T>, String)

    Sets the property and raises the PropertyChanging and PropertyChanged events.

    Declaration
    protected bool SetProperty<T>(T oldValue, T newValue, Action<T> callback, string propertyName = null)
    Parameters
    Type Name Description
    T oldValue

    The old value.

    T newValue

    The new value.

    Action<T> callback

    The callback to invoke to set the property.

    String propertyName

    The name of the property that has changed.

    Returns
    Type Description
    Boolean

    true if the property has changed, false otherwise.

    Type Parameters
    Name Description
    T

    The type of the property.

    Exceptions
    Type Condition
    ArgumentNullException

    callback is null.

    SetProperty<T>(T, T, EqualityComparer<T>, Action<T>, String)

    Sets the property and raises the PropertyChanging and PropertyChanged events.

    Declaration
    protected bool SetProperty<T>(T oldValue, T newValue, EqualityComparer<T> comparer, Action<T> callback, string propertyName = null)
    Parameters
    Type Name Description
    T oldValue

    The old value.

    T newValue

    The new value.

    EqualityComparer<T> comparer

    The comparer to use to check if the property has changed.

    Action<T> callback

    The callback to invoke to set the property.

    String propertyName

    The name of the property that has changed.

    Returns
    Type Description
    Boolean

    true if the property has changed, false otherwise.

    Type Parameters
    Name Description
    T

    The type of the property.

    Exceptions
    Type Condition
    ArgumentNullException

    callback or comparer is null.

    SetProperty<T>(ref T, T, EqualityComparer<T>, String)

    Sets the property and raises the PropertyChanging and PropertyChanged events.

    Declaration
    protected bool SetProperty<T>(ref T field, T newValue, EqualityComparer<T> comparer, string propertyName = null)
    Parameters
    Type Name Description
    T field

    The field to set.

    T newValue

    The new value.

    EqualityComparer<T> comparer

    The comparer to use to check if the property has changed.

    String propertyName

    The name of the property that has changed.

    Returns
    Type Description
    Boolean

    true if the property has changed, false otherwise.

    Type Parameters
    Name Description
    T

    The type of the property.

    Exceptions
    Type Condition
    ArgumentNullException

    comparer is null.

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

    Sets the property and raises the PropertyChanging and PropertyChanged events.

    Declaration
    protected bool SetProperty<T>(ref T field, T newValue, string propertyName = null)
    Parameters
    Type Name Description
    T field

    The field to set.

    T newValue

    The new value.

    String propertyName

    The name of the property that has changed.

    Returns
    Type Description
    Boolean

    true if the property has changed, false otherwise.

    Type Parameters
    Name Description
    T

    The type of the property.

    SetProperty<T, TModel>(T, T, TModel, Action<TModel, T>, String)

    Sets the property and raises the PropertyChanging and PropertyChanged events.

    Declaration
    protected bool SetProperty<T, TModel>(T oldValue, T newValue, TModel model, Action<TModel, T> callback, string propertyName = null)
    Parameters
    Type Name Description
    T oldValue

    The old value.

    T newValue

    The new value.

    TModel model

    The model to set the property on.

    Action<TModel, T> callback

    The callback to invoke to set the property.

    String propertyName

    The name of the property that has changed.

    Returns
    Type Description
    Boolean

    true if the property has changed, false otherwise.

    Type Parameters
    Name Description
    T

    The type of the property.

    TModel

    The type of the model.

    Exceptions
    Type Condition
    ArgumentNullException

    callback or model is null.

    Events

    PropertyChanged

    Occurs when a property value has changed.

    Declaration
    public event PropertyChangedEventHandler PropertyChanged
    Event Type
    Type Description
    PropertyChangedEventHandler
    Implements
    INotifyPropertyChanged.PropertyChanged

    PropertyChanging

    Occurs when a property value is changing.

    Declaration
    public event PropertyChangingEventHandler PropertyChanging
    Event Type
    Type Description
    PropertyChangingEventHandler
    Implements
    INotifyPropertyChanging.PropertyChanging
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023