FrameworkContentElement.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 bound property.

path
String

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

返回

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

示例

下面的示例通过创建一个新的自定义数据对象,将该对象建立为 DataContext,并将该对象的绑定路径设置为其内部的属性,来设置 Paragraph 元素的绑定。The following example sets a binding on a Paragraph element, by creating a new custom data object, establishing that object as DataContext, and setting the binding path to a property within it.

MyData myDataObject = new MyData();
myflowdocument.DataContext = myDataObject;
introParagraph.SetBinding(Paragraph.TagProperty, "CustomData");
Dim myDataObject As New MyData()
myflowdocument.DataContext = myDataObject
introParagraph.SetBinding(Paragraph.TagProperty, "CustomData")

注解

此方法是一种便捷方法,用于调用 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 bound property.

binding
BindingBase

表示数据绑定。Represents a data binding.

返回

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

示例

下面的示例通过创建新的 Binding 并将源设置为新生成的 DateTime 对象,来设置 Paragraph 元素上的绑定。The following example sets a binding on a Paragraph element, by creating a new Binding and setting the source to a newly built DateTime object.

DateTime myDataObject = new DateTime();
Binding myBinding = new Binding();
myBinding.Source = myDataObject;
introParagraph.SetBinding(Paragraph.TagProperty, myBinding);
Dim myDataObject As New Date()
Dim myBinding As New Binding()
myBinding.Source = myDataObject
introParagraph.SetBinding(Paragraph.TagProperty, myBinding)

注解

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

适用于