Binding to Plain Properties

Although the target property must be a dependency property, the source property can be any (public) property. This can be demonstrated with a slight twist to the previous example. In this case, the TextBlock next to the TextBox displays the number of characters in its text by binding to the simple Length property on the string Text property:

<StackPanel Orientation="Horizontal">  <!-- The user can type anything here -->  <TextBox Name="textBox"/>  <!-- This displays the # of characters -->  <TextBlock>    <Run>Characters used: </Run>    <Run Text="{Binding ElementName=textBox, Path=Text.Length}"/>  </TextBlock></StackPanel>

In this case, the character count automatically stays up-to-date, ...

Get XAML Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.