开发者

wpf: TextChanged event fired on setting DataContext

I've got a simple View with a single textbox that gets databound to a simple ViewModel with a single string property.

I need to catc开发者_C百科h the TextChanged event of that textbox so that I can do a little validation magic.

The problem that I am running into is that the TextChanged event fires for that textbox when the DataContext is set for the View.

Is there a standard mechanism that I can use to determine if the event is firing because of the DataContext being set versus when the user is making changes?

Thanks!


As far as I know there is no such mechanism. What you should do instead is to do your validation magic using standard means of WPF. Please see the following link: http://msdn.microsoft.com/en-us/library/ms752347.aspx#data_validation.

Anyway, as long as you use MVVM you can always detect that text has changed in the setter of the bound property in your view model.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜