Este contenido no se encuentra disponible en su idioma, pero aquí tiene la versión en inglés.

FrameworkElement.SetBinding Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Attaches a binding to a FrameworkElement, using the provided binding object, and returns a BindingExpressionBase for possible later use.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

Public Function SetBinding ( _
	dp As DependencyProperty, _
	binding As Binding _
) As BindingExpressionBase


Type: System.Windows.DependencyProperty
The dependency property identifier of the property that is data bound.
Type: System.Windows.Data.Binding
The binding to use for the property.


binding is specified as TwoWay, but has an empty Path.


dp or binding parameters are Nothing.

The returned binding expression is not necessary for many of the common binding scenarios, but is potentially useful for scenarios such as updating the source manually, or getting references to the parent Binding after the expression is created. The BindingExpressionBase class is a base class. In most cases you should attempt to cast the return value to BindingExpression, which is the class that implements the relevant API for the mentioned update or Binding parent scenarios.

For target bindings on dependency properties that are not a property of a FrameworkElement and therefore do not support SetBinding, you can use methods of BindingOperations instead.


Calling this method and passing in a new Binding object will not necessarily remove an existing binding. Instead, you should use the DependencyObject.ClearValue method.

The following example establishes a binding to a dependency property on an object by calling SetBinding.

'Create the source string 
Dim s As String = "Hello"

'Create the binding description 
Dim b As New Binding("")
b.Mode = BindingMode.OneTime
b.Source = s

'Attach the binding to the target 
MyText.SetBinding(TextBlock.TextProperty, b)

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone