开发者

WPF DatePicker UpdateSourceTrigger PropertyChanged not working

开发者 https://www.devze.com 2023-02-01 23:15 出处:网络
I am using MVVM and want to enable a button on text change of datepicker control.. XAML Code: Binding on DatePicker

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.


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

0

精彩评论

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