WPF DatePicker UpdateSourceTrigger PropertyChanged not working

updatesourcetriggerwpf

I am using MVVM and want to enable a button on text change of datepicker control..

XAML Code:
Binding on DatePicker

SelectedDate="{Binding InactiveDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
DisplayDate="{Binding InactiveDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">

Binding on Button:

<Button Margin="10" Command="{Binding SubmitCommand}"

View Model Code:
I am using a DelegateCommand for button click

View Model Delegate Initialization

SubmitCommand = new DelegateCommand(OnSubmitRequested, AllowSubmit, Controller);

The AllowSubmit implementation

private bool AllowSubmit()
{
    return InactiveDate != null;
}

InactiveDate Property implementation

    public DateTime? InactiveDate
    {
        get
        {
            return _inactiveDate;
        }

        set
        {
            _inactiveDate = value;
            SubmitCommand.RaiseCanExecuteChanged();
            PropertyChanged(this, new PropertyChangedEventArgs("InactiveDate"));
        }
    }

SubmitCommand.RaiseCanExecuteChanged() should enable the button once I enter any character on DateTimePicker but it is not happening.

Best Answer

Selected Date property does not work properly. I might be a bit late now, but you can use CurrentDateTimeText property of RadDatePicker

Related Topic