There are some powerful data editing controls in Silverlight such as the DataForm which let you define templates for ReadOnly and Edit modes, but sometimes you just need a simple way to view and update text. I came across a scenario in a custom application that required a simple way to view and edit text. The solution I came up with was a “Click to Edit” TextBlock. In the default state, the text is displayed as a read-only TextBlock, but you can simply click on the TextBlock for it to become an editable TextBox.
Here is a working example (Silverlight 5 plugin required):
To accomplish this, I built a UserControl that has both a TextBlock and a TextBox which are both bound to the same DependencyProperty for the Text value. Then I bind the visibility of each to an IsEditing DependencyProperty that gets toggled based on the focus state of the control.
Once this control is in place, using it is quite simple and you can bind the Text property as needed.
Latest posts by Josh Eastburn (see all)
- String Interpolation – Day 10 – Visual Studio 2015 - October 10, 2015
- Null-Conditional Operators – Day 2 – Visual Studio 2015 - October 2, 2015
- ngrok: Public URLs for your Dev Machine - May 14, 2015
- MSBuild with Atlassian Bamboo - May 8, 2015
- File Downloads with ASP.NET MVC - February 24, 2015