开发者

Silverlight StringFormat : remove format on focus (for edition)

开发者 https://www.devze.com 2023-04-09 00:39 出处:网络
I have a textbox twoway bound : <TextBox Text=\"{Binding Path=Cost, StringFormat=\\{0:N\\}, Mode=TwoWay}\" />

I have a textbox twoway bound :

<TextBox Text="{Binding Path=Cost, StringFormat=\{0:N\}, Mode=TwoWay}" />

When I put an amount (like 1000.1), and then change the focus, the number is formatted like I want (i.e. 1,000.10).

But when I focus on the textbox again, the text is still formatted. I'd like to be able to edit the original numeric input, not the formatted one (lose the commas in fact)

How can I achieve that ?

Edit : if the solution is applicable for all the textboxes, that wou开发者_JAVA百科ld be better than to edit the code behind for every one of them.


The easiest way to accomplish control enhancements like this is with a behavior. Just code up a behavior for a textbox and then give it two properties: One for the focused string format and one for the non-focused string format. Then hook into the GotFocus and LostFocus events and apply the formats to the Text property.

Let me know if you need some code samples to get you started.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号