开发者

Silverlight TextBox events to validate text input

开发者 https://www.devze.com 2023-04-12 06:09 出处:网络
Hello I\'m trying to handle开发者_运维技巧 the user\'s input to the TextBox in Silverlight. I need to catch the text that\'s been entered and if it is not valid dismiss it. I\'ve tried processing KeyD

Hello I'm trying to handle开发者_运维技巧 the user's input to the TextBox in Silverlight. I need to catch the text that's been entered and if it is not valid dismiss it. I've tried processing KeyDown and TextInputStart events, but the text gets updated after them. What should I do?


I think you better use Silverlight Validation with MVVM.

But if you prefer events, you can use the TextChanged Event to get every new character.

You can cast the sender in order the get the TextBox and use it's Text property.

For example:

    Dim l_textBox As TextBox = CType(sender, TextBox)
    if    l_textBox.Text = "ThisIsGoodString" Then
        ... Do something ...
    End If

(VB.NET code)

0

精彩评论

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