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

定义

创建 BindingExpressionBase 的新实例,并将其与指定的绑定目标属性关联。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

参数

target
DependencyObject DependencyObject DependencyObject DependencyObject

绑定的绑定目标。The binding target of the binding.

dp
DependencyProperty DependencyProperty DependencyProperty DependencyProperty

绑定的目标属性。The target property of the binding.

binding
BindingBase BindingBase BindingBase BindingBase

描述绑定的 BindingBase 对象。The BindingBase object that describes the binding.

返回

为指定的属性创建并与之相关联的 BindingExpressionBase 的实例。The instance of BindingExpressionBase created for and associated with the specified property. BindingExpressionBase 类是 BindingExpressionMultiBindingExpressionPriorityBindingExpression 的基类。The BindingExpressionBase class is the base class of BindingExpression, MultiBindingExpression, and PriorityBindingExpression.

异常

binding 参数不能为 nullThe binding parameter cannot be null.

示例

下面的示例演示如何使用此方法设置绑定。The following example shows how to use this method to set a binding. 在此示例中myNewBindDef ,是Binding一个描述绑定的对象。In this example, myNewBindDef is a Binding object that describes the binding. 绑定目标是myDateText TextBlock类的实例。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)

注解

此方法创建的新实例BindingExpressionBase ,并将该实例与给定对象的给定依赖项属性相关联。This method creates a new instance of a BindingExpressionBase and associates the instance with the given dependency property of the given object. 此方法是将绑定附加到可能不会公开其DependencyObject自己的 SetBinding 方法的任意的方式。This method is the way to attach a binding to an arbitrary DependencyObject that may not expose its own SetBinding method.

适用于