Επεξεργασία

Κοινή χρήση μέσω


BindingOperations.SetBinding 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

The binding target of the binding.

dp
DependencyProperty

The target property of the binding.

binding
BindingBase

The BindingBase object that describes the binding.

Returns

The instance of BindingExpressionBase created for and associated with the specified property. The BindingExpressionBase class is the base class of BindingExpression, MultiBindingExpression, and PriorityBindingExpression.

Exceptions

The binding parameter cannot be null.

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