Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight 3
Binding Class
Binding Properties
 Source Property
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Silverlight 3

Other versions are also available for the following:
.NET Framework Class Library for Silverlight
Binding..::.Source Property

Gets or sets the data source for the binding.

Namespace:  System.Windows.Data
Assembly:  System.Windows (in System.Windows.dll)
Visual Basic (Declaration)
Public Property Source As Object
    Get
    Set
Visual Basic (Usage)
Dim instance As Binding
Dim value As Object

value = instance.Source

instance.Source = value
C#
public Object Source { get; set; }
XAML Attribute Usage
<Binding Source="sourceReference"/>

XAML Values

sourceReference

A reference to an existing object that serves as the data source. Typically the object is created in a ResourceDictionary and given a key, then referenced by using the StaticResource markup extension. For instance: <Binding Source="{StaticResource customDataSourceObject}" .../>

Property Value

Type: System..::.Object
The source object that contains the data for the binding.
ExceptionCondition
InvalidOperationException

The Binding has already been attached to a target element, and cannot be modified.

-or-

The ElementName or RelativeSource property has already been set.

The Source property is optional on a Binding object. If the Source property is set on a Binding object, the data source applies only to the target properties that use that Binding object.

To create a data source that is inherited by all the child elements in the tree, instead set the DataContext property on the parent element. Then the parent element and all its children look to the DataContext as the source of their bindings. If the Source is set for a child element, it will override the DataContext inheritance in that instance.

The target can bind directly to the Source object if the path is empty or to a property of the Source object as defined by the path. The path is set either in XAML with the binding syntax or when the Binding object is created.

XAML Usage Notes

See Binding Markup Extension to learn how Source can be set as a binding property through the Binding markup extension, which enables specifying an entire Binding as an attribute string.

Property element syntax to create an object element that fills a Binding.Source property element is possible, but uncommon.

Source, RelativeSource, and ElementName are mutually exclusive in a binding. If you have set one of these attributes, then setting either of the other two in a binding (through XAML or through code) will cause an exception.

Visual Basic
'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)
C#
//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);

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker