FrameworkElement.SetBinding method

This topic has not yet been rated - Rate this topic

Attaches a binding to a FrameworkElement, using the provided binding object.

Syntax


public void SetBinding(
  DependencyProperty dp, 
  BindingBase binding
)

Parameters

dp

Type: DependencyProperty

The dependency property identifier of the property that is data bound.

binding

Type: BindingBase

The binding to use for the property.

Remarks

This method is a convenience method that simply calls BindingOperations.SetBinding, passing the current instance as the target parameter.

The type of the binding parameter is BindingBase for compatibility reasons, but in the Windows Runtime you always pass a Binding instance. Binding is derived from BindingBase.

The dp parameter takes a dependency property identifier. For more info on dependency properties and how a DependencyProperty value serves as the identifier, see Dependency properties overview.

Examples

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


// Create the source string.
string s = "Hello";

// Create the binding description.
Binding b = new Binding();
b.Mode = BindingMode.OneTime;
b.Source = s;

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


Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Namespace

Windows.UI.Xaml
Windows::UI::Xaml [C++]

Metadata

Windows.winmd

See also

FrameworkElement
Binding
BindingOperations
Data binding overview
Dependency properties overview

 

 

Build date: 1/31/2013

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.