FrameworkElement.SetBinding 方法

定义

为指定的依赖属性向此元素附加一个绑定。Attaches a binding to this element for the specified dependency property.

重载

SetBinding(DependencyProperty, String)

将提供的源属性名作为数据源的路径限定,从而将绑定附加到此元素上。Attaches a binding to this element, based on the provided source property name as a path qualification to the data source.

SetBinding(DependencyProperty, BindingBase)

基于已提供的绑定对象将一个绑定附加到此元素上。Attaches a binding to this element, based on the provided binding object.

SetBinding(DependencyProperty, String)

将提供的源属性名作为数据源的路径限定,从而将绑定附加到此元素上。Attaches a binding to this element, based on the provided source property name as a path qualification to the data source.

public:
 System::Windows::Data::BindingExpression ^ SetBinding(System::Windows::DependencyProperty ^ dp, System::String ^ path);
public System.Windows.Data.BindingExpression SetBinding (System.Windows.DependencyProperty dp, string path);
member this.SetBinding : System.Windows.DependencyProperty * string -> System.Windows.Data.BindingExpression
Public Function SetBinding (dp As DependencyProperty, path As String) As BindingExpression

参数

dp
DependencyProperty

标识应该建立绑定的目标属性。Identifies the destination property where the binding should be established.

path
String

源属性名称或用于绑定的属性的路径。The source property name or the path to the property used for the binding.

返回

BindingExpression

记录绑定的条件。Records the conditions of the binding. 此返回值可用于错误检查。This return value can be useful for error checking.

示例

下面的示例使用特定路径设置绑定。The following example sets a binding using a specific path.

myDataObject = new MyData(System.DateTime.Now);
root.DataContext = myDataObject;
myText.SetBinding(TextBlock.TextProperty, "MyDataProperty");
myDataObject = New MyData(Date.Now)
root.DataContext = myDataObject
myText.SetBinding(TextBlock.TextProperty, "MyDataProperty")

注解

此方法是一种便捷方法,用于调用 BindingOperations.SetBinding,该方法将当前实例作为 DependencyObject传递,并基于提供的 path 参数创建新的 BindingThis method is a convenience method for calling BindingOperations.SetBinding, which passes the current instance as the DependencyObject, and creates a new Binding based on the provided path parameter. 如果要建立简单的默认绑定,此签名更方便。This signature is more convenient if you are establishing a simple default binding. 如果需要指定任何非默认条件的绑定属性,或者要使用 MultiBindingPriorityBinding,则应使用 SetBinding(DependencyProperty, BindingBase) 签名。If you need to specify any binding properties to non-default conditions, or want to use a MultiBinding or PriorityBinding,you should use the SetBinding(DependencyProperty, BindingBase) signature.

SetBinding(DependencyProperty, BindingBase)

基于已提供的绑定对象将一个绑定附加到此元素上。Attaches a binding to this element, based on the provided binding object.

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

参数

dp
DependencyProperty

标识应在其中建立绑定的属性。Identifies the property where the binding should be established.

binding
BindingBase

表示数据绑定的详细信息。Represents the specifics of the data binding.

返回

BindingExpressionBase

记录绑定的条件。Records the conditions of the binding. 此返回值可用于错误检查。This return value can be useful for error checking.

注解

此方法是一种便捷方法,用于调用 BindingOperations.SetBinding,后者将当前实例作为 DependencyObject传递。This method is a convenience method for calling BindingOperations.SetBinding, which passes the current instance as the DependencyObject.

适用于