WPF Avalon 控制日期选择器绑定

发布于 2024-12-20 23:55:36 字数 717 浏览 4 评论 0原文

我正在使用具有 MVVM 模式的 Avalon DatePicker 控件。 我将此控件的 CurrentSelectedDate 绑定到我的 ViewModel 中的一个属性,如下所示:

<my:DatePicker x:Name="dtpBirthDate" Cursor="Hand" DatesSelectionMode="Single"   OverridesDefaultStyle="False"  CurrentlySelectedDate="{Binding Path=BirthDate}" />

其中 BirthDate 是我的 ViewModel 类中 DateTime 类型的属性:

public DateTime BirthDate
    {
        get { return _patient.BirthDate; }
        set
        {
            if (value == _patient.BirthDate)
                return;

            _patient.BirthDate = value;

            base.OnPropertyChanged("BirthDate");
        }
    }

不过,当我从用户界面更改值时,不会发生此属性的更改。 有人可以解释一下我做错了什么吗? 我仅限于 .NET 3.0。

I am using the Avalon DatePicker Control with MVVM pattern.
I am binding this control's CurrentlySelectedDate to a property from my ViewModel like so:

<my:DatePicker x:Name="dtpBirthDate" Cursor="Hand" DatesSelectionMode="Single"   OverridesDefaultStyle="False"  CurrentlySelectedDate="{Binding Path=BirthDate}" />

where BirthDate is a property of type DateTime in my ViewModel class:

public DateTime BirthDate
    {
        get { return _patient.BirthDate; }
        set
        {
            if (value == _patient.BirthDate)
                return;

            _patient.BirthDate = value;

            base.OnPropertyChanged("BirthDate");
        }
    }

Still, the change of this property does not occur when I change the value from the user interface.
Can someone explain me what I did wrong?
I am restricted to .NET 3.0.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白衬杉格子梦 2024-12-27 23:55:36

解决方案是添加 UpdateSourceTrigger=PropertyChanged, Mode=TwoWay,如下所示:

<my:DatePicker x:Name="dtpBirthDate" Cursor="Hand" DatesSelectionMode="Single"
                   OverridesDefaultStyle="False"
                   CurrentlySelectedDate="{Binding Path=BirthDate,    ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
                   Validation.ErrorTemplate="{x:Null}"></my:DatePicker>

the solution was to add the UpdateSourceTrigger=PropertyChanged, Mode=TwoWay like so:

<my:DatePicker x:Name="dtpBirthDate" Cursor="Hand" DatesSelectionMode="Single"
                   OverridesDefaultStyle="False"
                   CurrentlySelectedDate="{Binding Path=BirthDate,    ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
                   Validation.ErrorTemplate="{x:Null}"></my:DatePicker>
你如我软肋 2024-12-27 23:55:36

请尝试将 BirthDate 绑定到 SelectedDate 属性而不是 CurrentSelectedDate。

问候

Please, try to bind the BirthDate to the SelectedDate property instead of CurrentlySelectedDate.

Regards

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文