Class ObservableObject
A base class for objects of which the properties must be observable.
Inherited Members
Namespace: Unity.AppUI.MVVM
Assembly: Unity.AppUI.MVVM.dll
Syntax
public abstract class ObservableObject : INotifyPropertyChanged, INotifyPropertyChanging
Remarks
Starting Unity 6, you can implement the UnityEngine.UIElements.IDataSourceViewHashProvider interface in your derived ObservableObject class to provide a hash for the data source view. That will give you the ability to control the data source view's update behavior (instead of always updating the view when the data source changes).
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 |
|
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 |
|
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 |
|---|---|
| bool |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the property. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
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 |
|---|---|
| bool |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the property. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
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 |
|---|---|
| bool |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the property. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
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 |
|---|---|
| bool |
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 |
|---|---|
| bool |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the property. |
| TModel | The type of the model. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
Events
PropertyChanged
Occurs when a property value has changed.
Declaration
public event PropertyChangedEventHandler? PropertyChanged
Event Type
| Type | Description |
|---|---|
| PropertyChangedEventHandler |
PropertyChanging
Occurs when a property value is changing.
Declaration
public event PropertyChangingEventHandler? PropertyChanging
Event Type
| Type | Description |
|---|---|
| PropertyChangingEventHandler |