ObservableObject.SetPropertyAndNotifyOnCompletion Method

Definition

Overloads

SetPropertyAndNotifyOnCompletion(ObservableObject+TaskNotifier, Task, String)

Compares the current and new values for a given field (which should be the backing field for a property). If the value has changed, raises the PropertyChanging event, updates the field and then raises the PropertyChanged event. The behavior mirrors that of SetProperty<T>(T, T, String), with the difference being that this method will also monitor the new value of the property (a generic Task) and will also raise the PropertyChanged again for the target property when it completes. This can be used to update bindings observing that Task or any of its properties. This method and its overload specifically rely on the ObservableObject.TaskNotifier type, which needs to be used in the backing field for the target Task property. The field doesn't need to be initialized, as this method will take care of doing that automatically. The ObservableObject.TaskNotifier type also includes an implicit operator, so it can be assigned to any Task instance directly. Here is a sample property declaration using this method:

private TaskNotifier myTask;

public Task MyTask
{
    get => myTask;
    private set => SetAndNotifyOnCompletion(ref myTask, value);
}
SetPropertyAndNotifyOnCompletion(ObservableObject+TaskNotifier, Task, Action<Task>, String)

Compares the current and new values for a given field (which should be the backing field for a property). If the value has changed, raises the PropertyChanging event, updates the field and then raises the PropertyChanged event. This method is just like SetPropertyAndNotifyOnCompletion(ObservableObject+TaskNotifier, Task, String), with the difference being an extra Action<T> parameter with a callback being invoked either immediately, if the new task has already completed or is null, or upon completion.

SetPropertyAndNotifyOnCompletion<T>(ObservableObject.TaskNotifier<T>, Task<T>, String)

Compares the current and new values for a given field (which should be the backing field for a property). If the value has changed, raises the PropertyChanging event, updates the field and then raises the PropertyChanged event. The behavior mirrors that of SetProperty<T>(T, T, String), with the difference being that this method will also monitor the new value of the property (a generic Task) and will also raise the PropertyChanged again for the target property when it completes. This can be used to update bindings observing that Task or any of its properties. This method and its overload specifically rely on the ObservableObject.TaskNotifier<T> type, which needs to be used in the backing field for the target Task property. The field doesn't need to be initialized, as this method will take care of doing that automatically. The ObservableObject.TaskNotifier<T> type also includes an implicit operator, so it can be assigned to any Task instance directly. Here is a sample property declaration using this method:

private TaskNotifier<int> myTask;

public Task<int> MyTask
{
    get => myTask;
    private set => SetAndNotifyOnCompletion(ref myTask, value);
}
SetPropertyAndNotifyOnCompletion<T>(ObservableObject.TaskNotifier<T>, Task<T>, Action<Task<T>>, String)

Compares the current and new values for a given field (which should be the backing field for a property). If the value has changed, raises the PropertyChanging event, updates the field and then raises the PropertyChanged event. This method is just like SetPropertyAndNotifyOnCompletion<T>(ObservableObject.TaskNotifier<T>, Task<T>, String), with the difference being an extra Action<T> parameter with a callback being invoked either immediately, if the new task has already completed or is null, or upon completion.

SetPropertyAndNotifyOnCompletion(ObservableObject+TaskNotifier, Task, String)

Compares the current and new values for a given field (which should be the backing field for a property). If the value has changed, raises the PropertyChanging event, updates the field and then raises the PropertyChanged event. The behavior mirrors that of SetProperty<T>(T, T, String), with the difference being that this method will also monitor the new value of the property (a generic Task) and will also raise the PropertyChanged again for the target property when it completes. This can be used to update bindings observing that Task or any of its properties. This method and its overload specifically rely on the ObservableObject.TaskNotifier type, which needs to be used in the backing field for the target Task property. The field doesn't need to be initialized, as this method will take care of doing that automatically. The ObservableObject.TaskNotifier type also includes an implicit operator, so it can be assigned to any Task instance directly. Here is a sample property declaration using this method:

private TaskNotifier myTask;

public Task MyTask
{
    get => myTask;
    private set => SetAndNotifyOnCompletion(ref myTask, value);
}
protected bool SetPropertyAndNotifyOnCompletion (ref CommunityToolkit.Mvvm.ComponentModel.ObservableObject.TaskNotifier? taskNotifier, System.Threading.Tasks.Task? newValue, string? propertyName = default);
member this.SetPropertyAndNotifyOnCompletion : TaskNotifier * System.Threading.Tasks.Task * string -> bool
Protected Function SetPropertyAndNotifyOnCompletion (ByRef taskNotifier As ObservableObject.TaskNotifier, newValue As Task, Optional propertyName As String = Nothing) As Boolean

Parameters

taskNotifier
ObservableObject.TaskNotifier

The field notifier to modify.

newValue
Task

The property's value after the change occurred.

propertyName
String

(optional) The name of the property that changed.

Returns

true if the property was changed, false otherwise.

Remarks

The PropertyChanging and PropertyChanged events are not raised if the current and new value for the target property are the same. The return value being true only indicates that the new value being assigned to taskNotifier is different than the previous one, and it does not mean the new Task instance passed as argument is in any particular state.

Applies to

SetPropertyAndNotifyOnCompletion(ObservableObject+TaskNotifier, Task, Action<Task>, String)

Compares the current and new values for a given field (which should be the backing field for a property). If the value has changed, raises the PropertyChanging event, updates the field and then raises the PropertyChanged event. This method is just like SetPropertyAndNotifyOnCompletion(ObservableObject+TaskNotifier, Task, String), with the difference being an extra Action<T> parameter with a callback being invoked either immediately, if the new task has already completed or is null, or upon completion.

protected bool SetPropertyAndNotifyOnCompletion (ref CommunityToolkit.Mvvm.ComponentModel.ObservableObject.TaskNotifier? taskNotifier, System.Threading.Tasks.Task? newValue, Action<System.Threading.Tasks.Task?> callback, string? propertyName = default);
member this.SetPropertyAndNotifyOnCompletion : TaskNotifier * System.Threading.Tasks.Task * Action<System.Threading.Tasks.Task> * string -> bool
Protected Function SetPropertyAndNotifyOnCompletion (ByRef taskNotifier As ObservableObject.TaskNotifier, newValue As Task, callback As Action(Of Task), Optional propertyName As String = Nothing) As Boolean

Parameters

taskNotifier
ObservableObject.TaskNotifier

The field notifier to modify.

newValue
Task

The property's value after the change occurred.

callback
Action<Task>

A callback to invoke to update the property value.

propertyName
String

(optional) The name of the property that changed.

Returns

true if the property was changed, false otherwise.

Remarks

The PropertyChanging and PropertyChanged events are not raised if the current and new value for the target property are the same.

Applies to

SetPropertyAndNotifyOnCompletion<T>(ObservableObject.TaskNotifier<T>, Task<T>, String)

Compares the current and new values for a given field (which should be the backing field for a property). If the value has changed, raises the PropertyChanging event, updates the field and then raises the PropertyChanged event. The behavior mirrors that of SetProperty<T>(T, T, String), with the difference being that this method will also monitor the new value of the property (a generic Task) and will also raise the PropertyChanged again for the target property when it completes. This can be used to update bindings observing that Task or any of its properties. This method and its overload specifically rely on the ObservableObject.TaskNotifier<T> type, which needs to be used in the backing field for the target Task property. The field doesn't need to be initialized, as this method will take care of doing that automatically. The ObservableObject.TaskNotifier<T> type also includes an implicit operator, so it can be assigned to any Task instance directly. Here is a sample property declaration using this method:

private TaskNotifier<int> myTask;

public Task<int> MyTask
{
    get => myTask;
    private set => SetAndNotifyOnCompletion(ref myTask, value);
}
protected bool SetPropertyAndNotifyOnCompletion<T> (ref CommunityToolkit.Mvvm.ComponentModel.ObservableObject.TaskNotifier<T>? taskNotifier, System.Threading.Tasks.Task<T>? newValue, string? propertyName = default);
member this.SetPropertyAndNotifyOnCompletion : TaskNotifier * System.Threading.Tasks.Task<'T> * string -> bool
Protected Function SetPropertyAndNotifyOnCompletion(Of T) (ByRef taskNotifier As ObservableObject.TaskNotifier(Of T), newValue As Task(Of T), Optional propertyName As String = Nothing) As Boolean

Type Parameters

T

The type of result for the Task<TResult> to set and monitor.

Parameters

taskNotifier
ObservableObject.TaskNotifier<T>

The field notifier to modify.

newValue
Task<T>

The property's value after the change occurred.

propertyName
String

(optional) The name of the property that changed.

Returns

true if the property was changed, false otherwise.

Remarks

The PropertyChanging and PropertyChanged events are not raised if the current and new value for the target property are the same. The return value being true only indicates that the new value being assigned to taskNotifier is different than the previous one, and it does not mean the new Task<TResult> instance passed as argument is in any particular state.

Applies to

SetPropertyAndNotifyOnCompletion<T>(ObservableObject.TaskNotifier<T>, Task<T>, Action<Task<T>>, String)

Compares the current and new values for a given field (which should be the backing field for a property). If the value has changed, raises the PropertyChanging event, updates the field and then raises the PropertyChanged event. This method is just like SetPropertyAndNotifyOnCompletion<T>(ObservableObject.TaskNotifier<T>, Task<T>, String), with the difference being an extra Action<T> parameter with a callback being invoked either immediately, if the new task has already completed or is null, or upon completion.

protected bool SetPropertyAndNotifyOnCompletion<T> (ref CommunityToolkit.Mvvm.ComponentModel.ObservableObject.TaskNotifier<T>? taskNotifier, System.Threading.Tasks.Task<T>? newValue, Action<System.Threading.Tasks.Task<T>?> callback, string? propertyName = default);
member this.SetPropertyAndNotifyOnCompletion : TaskNotifier * System.Threading.Tasks.Task<'T> * Action<System.Threading.Tasks.Task<'T>> * string -> bool
Protected Function SetPropertyAndNotifyOnCompletion(Of T) (ByRef taskNotifier As ObservableObject.TaskNotifier(Of T), newValue As Task(Of T), callback As Action(Of Task(Of T)), Optional propertyName As String = Nothing) As Boolean

Type Parameters

T

The type of result for the Task<TResult> to set and monitor.

Parameters

taskNotifier
ObservableObject.TaskNotifier<T>

The field notifier to modify.

newValue
Task<T>

The property's value after the change occurred.

callback
Action<Task<T>>

A callback to invoke to update the property value.

propertyName
String

(optional) The name of the property that changed.

Returns

true if the property was changed, false otherwise.

Remarks

The PropertyChanging and PropertyChanged events are not raised if the current and new value for the target property are the same.

Applies to