How can I validate multiple properties when any of them changes?

后端 未结 4 1514

I have two date fields: StartDate and EndDate. StartDate must be earlier than EndDate.

If the user changes the StartDate to something greater than the EndDate, a red

4条回答
  •  难免孤独
    2020-12-08 15:52

    I generally add all of my validation errors to a dictionary, and have the validation template subscribe to that via the property name. In each property changed event handler, I can check any number of properties and add or remove their validation status as necessary.

    Check this answer for how my implementation looks. Sorry it is in VB.NET, but should be fairly straightforward.

提交回复
热议问题