CommandBindingsCollectionAddSynchronizedPropertyBinding(Object, String, String, Boolean, Object) Method

Creates a special binding for the PropertyChanged or sourcePropertyNameChanged event of the specified source, which allows to update the specified targetPropertyName in the targets, when the property of sourcePropertyName changes in the source. The target properties will be set using the SynchronizationContext of the thread on which this method was called.

Definition

Namespace: KGySoft.ComponentModel
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.0.0
C#
public ICommandBinding AddSynchronizedPropertyBinding(
	Object source,
	string sourcePropertyName,
	string targetPropertyName,
	bool awaitCompletion,
	params Object[]? targets
)

Parameters

source  Object
The source object, whose property specified by the sourcePropertyName parameter is observed.
sourcePropertyName  String
The name of the property, whose change is observed.
targetPropertyName  String
The name of the property in the target object(s).
awaitCompletion  Boolean
to block the thread of the triggering event until setting a target property is completed; otherwise, .
targets  Object
The targets to be updated. If the concrete instances to update have to be returned when the change occurs use the ICommandBinding.AddTarget method on the result ICommandBinding instance.

Return Value

ICommandBinding
An ICommandBinding instance, to which the specified source and targets are bound.

Remarks

This method uses a prepared command internally, which is bound to the PropertyChanged event of the specified source object. Or, when source does not implement INotifyPropertyChanged, then an event of name sourcePropertyName postfixed by Changed should exist on the source object.

The ICommandState, which is created for the underlying command contains the specified property names. Do not remove these state entries; otherwise, the command will throw an InvalidOperationException when executed.

The property with targetPropertyName will be set in the specified targets immediately when this method is called. The targets, which are added later by the ICommandBinding.AddTarget methods, are set only when the PropertyChanged or sourcePropertyNameChanged event occurs on the source object.

Exceptions

ArgumentNullExceptionsource, sourcePropertyName or targetPropertyName is .
ArgumentExceptionsource is neither an INotifyPropertyChanged implementation nor has a sourcePropertyNameChanged event.

See Also