FrameworkElement.SetBinding FrameworkElement.SetBinding FrameworkElement.SetBinding FrameworkElement.SetBinding Method

定義

將繫結附加至指定相依性屬性的這個項目。Attaches a binding to this element for the specified dependency property.

多載

SetBinding(DependencyProperty, String) SetBinding(DependencyProperty, String) SetBinding(DependencyProperty, String) 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) SetBinding(DependencyProperty, BindingBase) SetBinding(DependencyProperty, BindingBase) SetBinding(DependencyProperty, BindingBase)

根據提供的繫結物件,將繫結附加至這個項目。Attaches a binding to this element, based on the provided binding object.

SetBinding(DependencyProperty, String) SetBinding(DependencyProperty, String) SetBinding(DependencyProperty, String) 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 DependencyProperty DependencyProperty DependencyProperty

識別要建立繫結的目的屬性。Identifies the destination property where the binding should be established.

path
String String String 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.

範例

下列範例會設定使用特定路徑的繫結。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,並建立新Binding根據所提供path參數。This 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. 如果您要指定非預設的條件,任何繫結屬性,或想要使用MultiBinding或是PriorityBinding,您應該使用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) SetBinding(DependencyProperty, BindingBase) SetBinding(DependencyProperty, BindingBase) 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 DependencyProperty DependencyProperty DependencyProperty

識別應該要建立繫結的屬性。Identifies the property where the binding should be established.

binding
BindingBase BindingBase BindingBase BindingBase

代表資料繫結的詳細規格。Represents the specifics of the data binding.

傳回

記錄繫結的條件。Records the conditions of the binding. 這個傳回值對錯誤檢查很有用。This return value can be useful for error checking.

備註

這個方法是很便利的方法呼叫BindingOperations.SetBinding,傳遞做為目前的執行個體DependencyObjectThis method is a convenience method for calling BindingOperations.SetBinding, which passes the current instance as the DependencyObject.

適用於