我们在Web中可能会遇到这样一种情况,就是在修改某个文本(如html中的input type="text")的值时,当文本聚焦时,会将文本全部选中,方便修改,而不需要一个个删除后修改。
我只将其中的代码贴出来,就不一步步详细说明了,大家可以通过Visual Studio 2010,或者Expression Blend去创建行为,上面两篇文章都有说明。
TextBoxSelectAllOnFocusBehavior.cs 代码
<a href="http://blog.51cto.com/attachment/201105/092239876.png" target="_blank"></a>
如果是使用VS去创建行为的,在调用行为时, 别忘了添加命名空间,具体可以参加下面的源代码。来看下运行效果吧
<a href="http://blog.51cto.com/attachment/201105/092300228.png" target="_blank"></a>
源代码下载:
<a target="_blank" href="http://alexis.blog.51cto.com/attachment/201105/2621421_1306459444.rar"></a>
参考
<a href="http://mark.monsterconsultancy.nl/2011/04/13/silverlight--windows-phone-7-behavior-to-enhance-usability-of-textboxes?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+MarkMonster+%28Mark+Monster%29">http://mark.monsterconsultancy.nl/2011/04/13/silverlight--windows-phone-7-behavior-to-enhance-usability-of-textboxes?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+MarkMonster+(Mark+Monster)</a>
<a href="http://down.51cto.com/data/2358247" target="_blank">附件:http://down.51cto.com/data/2358247</a>
本文转自xshf12345 51CTO博客,原文链接:http://blog.51cto.com/alexis/575302,如需转载请自行联系原作者