开发者

WPF How to access the ValidationResult object in the relevant control?

开发者 https://www.devze.com 2023-03-15 21:52 出处:网络
I want t开发者_运维知识库o use the ValidationResult object to send information back to the validated field on my form to reformat the data as necessary, for example:

I want t开发者_运维知识库o use the ValidationResult object to send information back to the validated field on my form to reformat the data as necessary, for example:

User enters (123)-456-7890 for the phone number, but in our database all phone numbers are of the format 123.456.7890. The ValidationResult object is created with the args (True, "Reformat") and then the logic of the textbox reformats the String into the proper format. Alternatively, I would be okay accessing the validated field's DP's from within the ValidationRule in order to accomplish the same sort of thing.

How could I do this?


This does not sound like a very good idea to me, since you have a binding to a property anyway i would suggest that reformatting logic is applied in the setter of said property. (The binding engine should get the value afterwards in .NET 4 so this fromatting should even be reflected in the control as well)

Alternatively you can use the Converter layer to accomplish the formatting.

0

精彩评论

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

关注公众号