Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
1 out of 1 rated this helpful - Rate this topic

How to: Create a Simple Binding

This example shows you how to create a simple Binding.

Example

In this example, you have a Person object with a string property named PersonName. The Person object is defined in the namespace called SDKSample.

The following example instantiates the Person object with a PersonName property value of Joe. This is done in the Resources section and assigned an x:Key.

<Window Name="root"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:src="clr-namespace:SDKSample"
  xmlns:system="clr-namespace:System;assembly=mscorlib"
  SizeToContent="WidthAndHeight"
  Title="Simple Data Binding Sample">

  <Window.Resources>
    <src:Person x:Key="myDataSource" PersonName="Joe"/>

	...

  </Window.Resources>

	...

</Window>

To bind to the PersonName property you would do the following:

<TextBlock Text="{Binding Source={StaticResource myDataSource}, Path=PersonName}"/>

As a result, the TextBlock appears with the value "Joe".

For the complete sample, see Simple Binding Sample.

See Also

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft. All rights reserved.