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

Definition

Attaches a binding to this element for the specified dependency property.

Overloads

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

Parameters

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.

Returns

Records the conditions of the binding. This return value can be useful for error checking.

Examples

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")

Remarks

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

Parameters

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.

Returns

Records the conditions of the binding. This return value can be useful for error checking.

Remarks

This method is a convenience method for calling BindingOperations.SetBinding, which passes the current instance as the DependencyObject.

Applies to