views:

98

answers:

1

My problem is with fields whose validation logic is linked - when Field A changes, how do I get Field B (which depends on it) to re-validate?

Here's a concrete example. Two DatePickers, one each for Start and End date, bound to the same data model object, as shown below.

public class Model
{
        private DateTime _startDate = DateTime.Now;
        private DateTime _endDate = DateTime.Now;

        public DateTime StartDate
        {
            get { return _startDate; }

            [DebuggerStepThrough]
            set
            {
                if (value < DateTime.Now)
                    throw new Exception("From date cannot be in the past");

                _startDate = value;
            }
        }

        public DateTime EndDate
        {
            get { return _endDate; }

            [DebuggerStepThrough]
            set
            {
                if (value < DateTime.Now)
                    throw new Exception("From date cannot be in the past");

                if (value < FromDate)
                    throw new Exception("To date cannot be earlier than from date");

                _endDate = value;
            }
        }
    }

Notice that the dates default to "today".

Now, if I set EndDate to "tomorrow" using the bound DatePicker control, then no error is raised (as expected).

However, if I then set StartDate to be the day after tomorrow then a user would expect the EndDate field to become invalid - but no validation exception is raised because EndDate hasn't changed.

Am I missing something completely obvious? Is there a simple way to get the UI to re-validate itself?

Or is this (common) case just not handled?

I can't find anything on the net about this, of course.

A: 

Hi Rammesses,

I just posted an nearly idenitcal question when I saw your post. Were you able to find a solution to this issue?

David Austin