BindingOperations BindingOperations BindingOperations Class


Provides the static SetBinding method.

public : sealed class BindingOperations : IBindingOperations
public sealed class BindingOperations : IBindingOperations
Public NotInheritable Class BindingOperations Implements IBindingOperations
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)


SetBinding(DependencyObject, DependencyProperty, BindingBase) SetBinding(DependencyObject, DependencyProperty, BindingBase) SetBinding(DependencyObject, DependencyProperty, BindingBase)

Associates a Binding with a target property on a target object. This method is the code equivalent to using a {Binding} markup extension in XAML markup.

public : static void SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
public static void SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
Public Static Function SetBinding(target As DependencyObject, dp As DependencyProperty, binding As BindingBase) As void
DependencyObject DependencyObject DependencyObject

The object that should be the target of the evaluated binding.

DependencyProperty DependencyProperty DependencyProperty

The property on the target to bind, specified by its identifier. These identifiers are usually available as static read-only properties on the type that defines the target object, or one of its base types. You can also bind to attached properties, but see Remarks.

BindingBase BindingBase BindingBase

The binding to assign to the target property. This Binding should be initialized: important Binding properties such as Path should already be set before passing it as the parameter.


You can bind to custom dependency properties or custom attached properties, the identifier you pass as the dp parameter doesn't have to be a Windows Runtime defined property.

BindingOperations.SetBinding is a static utility method, and does basically the same thing as FrameworkElement.SetBinding. It's more common to use FrameworkElement.SetBinding because it's an instance method. One important difference though is that BindingOperations.SetBinding can use a target value of any DependencyObject, whereas FrameworkElement.SetBinding can by definition only be used for a FrameworkElement target. This doesn't usually matter for most Windows Runtime classes used for XAML UI, because these are mostly FrameworkElement subclasses anyways. But the distinction might matter if you are targeting bindings on your own custom classes that derive from DependencyObject or UIElement.


Calling the SetBinding method and passing in a new Binding object won't necessarily remove an existing binding. Instead, you should first call the DependencyObject.ClearValue method, then call SetBinding.

Binding to attached properties

You can put data bindings on any attached properties that a target object supports. Technically an DependencyObject supports all the possible attached properties, but you'd usually only set a binding on an attached property that's relevant to that object or your scenario. For example you would set a binding on Grid.Row only if you anticipate that the target element has a Grid parent that will use that info. Specify the dp parameter as the dependency property identifier that exists on the attached property's owner class (for the Grid.Row example, that identifier is Grid.RowProperty ). You won't find that identifier on the target because it's an attached property. For more info on attached properties, see Attached properties overview.

See Also

See Also