Generally, when creating a binding, you'll be binding to a single property on the source object. For example, the DataContext
property of a TextBox control might be assigned a Person
object, and you might want to bind to the FirstName
property on that object, with the FirstName
property returning a string:
<TextBox Text="{Binding FirstName, Source={StaticResource personResource}}" />
However, what if the Person
object doesn't have a FirstName
property but instead has a Name
property that returns a PersonName
object, and it's this object that has the FirstName
property, meaning that you're effectively dealing with nested properties? How do you handle that sort of binding? This is possible by using the same style of dot notation you use in C# code to traverse down the object hierarchy:
<TextBox Text="{Binding Name.FirstName, Source={StaticResource personResource}}" />
You can traverse down multiple levels of the object hierarchy for as far as you need.