WPF Avalon 控制日期选择器绑定
我正在使用具有 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案是添加 UpdateSourceTrigger=PropertyChanged, Mode=TwoWay,如下所示:
the solution was to add the UpdateSourceTrigger=PropertyChanged, Mode=TwoWay like so:
请尝试将 BirthDate 绑定到 SelectedDate 属性而不是 CurrentSelectedDate。
问候
Please, try to bind the BirthDate to the SelectedDate property instead of CurrentlySelectedDate.
Regards