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.

適用於