BindingOperations.SetBinding(DependencyObject, DependencyProperty, BindingBase) BindingOperations.SetBinding(DependencyObject, DependencyProperty, BindingBase) BindingOperations.SetBinding(DependencyObject, DependencyProperty, BindingBase) BindingOperations.SetBinding(DependencyObject, DependencyProperty, BindingBase) Method

Definition

Creates and associates a new instance of BindingExpressionBase with the specified binding target property.

public:
 static System::Windows::Data::BindingExpressionBase ^ SetBinding(System::Windows::DependencyObject ^ target, System::Windows::DependencyProperty ^ dp, System::Windows::Data::BindingBase ^ binding);
public static System.Windows.Data.BindingExpressionBase SetBinding (System.Windows.DependencyObject target, System.Windows.DependencyProperty dp, System.Windows.Data.BindingBase binding);
static member SetBinding : System.Windows.DependencyObject * System.Windows.DependencyProperty * System.Windows.Data.BindingBase -> System.Windows.Data.BindingExpressionBase
Public Shared Function SetBinding (target As DependencyObject, dp As DependencyProperty, binding As BindingBase) As BindingExpressionBase

Parameters

target
DependencyObject DependencyObject DependencyObject DependencyObject

The binding target of the binding.

binding
BindingBase BindingBase BindingBase BindingBase

The BindingBase object that describes the binding.

Returns

Exceptions

Examples

The following example shows how to use this method to set a binding. In this example, myNewBindDef is a Binding object that describes the binding. The binding target is myDateText, an instance of the TextBlock class.

  // myDatetext is a TextBlock object that is the binding target object
BindingOperations.SetBinding(myDateText, TextBlock.TextProperty, myNewBindDef);
BindingOperations.SetBinding(myDateText, TextBlock.ForegroundProperty, myNewBindDef);
' myDatetext is a TextBlock object that is the binding target object
     BindingOperations.SetBinding(myDateText, TextBlock.TextProperty, myNewBindDef)
     BindingOperations.SetBinding(myDateText, TextBlock.ForegroundProperty, myNewBindDef)

Remarks

This method creates a new instance of a BindingExpressionBase and associates the instance with the given dependency property of the given object. This method is the way to attach a binding to an arbitrary DependencyObject that may not expose its own SetBinding method.

Applies to