CommandCreateSynchronizedPropertyBinding(INotifyPropertyChanged, String, String, FuncObject, Object, Boolean, Object) Method

Creates a special binding for the PropertyChanged 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: 9.0.0
C#
public static ICommandBinding CreateSynchronizedPropertyBinding(
	this INotifyPropertyChanged source,
	string sourcePropertyName,
	string targetPropertyName,
	Func<Object?, Object?>? format,
	bool awaitCompletion,
	params Object[]? targets
)

Parameters

source  INotifyPropertyChanged
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).
format  FuncObject, Object
If not , then can be used to format the value to be set in the targets.
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.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type INotifyPropertyChanged. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

This method uses a prepared command internally, which is bound to the PropertyChanged event of the specified source object.

The ICommandState, which is created for the underlying command contains the specified property names and formatparameters. 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 event occurs on the source object.

Exceptions

ArgumentNullExceptionsource, sourcePropertyName or targetPropertyName is .

See Also