Redigera

Dela via


FrameworkContentElement.SetBinding Method

Definition

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

Overloads

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)

Attaches a binding to this element, based on the provided binding object.

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

Identifies the bound property.

path
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 on a Paragraph element, by creating a new custom data object, establishing that object as DataContext, and setting the binding path to a property within it.

MyData myDataObject = new MyData();
myflowdocument.DataContext = myDataObject;
introParagraph.SetBinding(Paragraph.TagProperty, "CustomData");
Dim myDataObject As New MyData()
myflowdocument.DataContext = myDataObject
introParagraph.SetBinding(Paragraph.TagProperty, "CustomData")

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.

Applies to

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

Identifies the bound property.

binding
BindingBase

Represents a data binding.

Returns

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

Examples

The following example sets a binding on a Paragraph element, by creating a new Binding and setting the source to a newly built DateTime object.

DateTime myDataObject = new DateTime();
Binding myBinding = new Binding();
myBinding.Source = myDataObject;
introParagraph.SetBinding(Paragraph.TagProperty, myBinding);
Dim myDataObject As New Date()
Dim myBinding As New Binding()
myBinding.Source = myDataObject
introParagraph.SetBinding(Paragraph.TagProperty, myBinding)

Remarks

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

Applies to