Display running count of characters entered in silverlight


Display running count of characters entered in silverlight. This code snippet shows how we can display running count of number of characters entered by the user in a TextBox in silverlight. We need to Bind the Text.Length property of the element to a textblock which displays the running count of number of characters entered by the user.

Display running count of characters entered in a textblock in silverlight application.

This code snippet shows how we can display running count of number of characters entered by the user in a TextBox in silverlight.


<StackPanel Orientation="Vertical" Margin="50" >
<TextBlock Text="Max 500 characters allowed)" />
<TextBox x:Name="txtDemo" MaxLength="500" Text="My Demo"/>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Text.Length, ElementName=txtDemo}" />
<TextBlock Text=" of " />
<TextBlock Text="{Binding MaxLength, ElementName=txtDemo}" />
</StackPanel>
</StackPanel>



In the above code,
1. "txtDemo" is the TextBox which allows maximum of 500 characters to be entered by the user.
2. We need to Bind the Text.Length property of the element "txtDemo" to a textblock which displays the running count of number of characters entered by the user.
3. MaxLength property specifies how many characters are allowed to be entered by the user.


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: