tags:

views:

152

answers:

2

My DataTemplate for my ListBox has a TextBlock in it. If I click on the TextBlock, I want it to change to a TextBox so I can edit it. Is there a good way to do this?

A: 

You should be able to use two-way binding of the text. Then, any edits to the Text dependency property for the item should be reflected back to the original data object.

In your DataTemplate, you probably have something like

<TextBox Text="{Binding}" />

Could you try making this

<TextBox Text="{Binding Mode=TwoWay}" />

Unfortunately I am on a machine without the Silverlight SDK on it at the moment, so I can't verify if my syntax is correct on the binding.

Jeff Wilcox
A TextBlock is not editable. That's why I want to change it to a TextBox so I can edit it. Then the TwoWay binding works like it's supposed to.
Scott
Whoops, my bad. TextBox with a two-way binding should get you there.
Jeff Wilcox
+1  A: 

You may get some ideas here: Tim heuer's editable ListBox

devMomentum