【发布时间】:2011-07-11 20:36:36
【问题描述】:
我正在尝试在日期时间选择器控件中验证所选日期,如果所选日期为 > Datetime.Today,则将其设置为今天的日期。我面临的问题是我无法设置 SelectedDate通过 xaml 获取 datetimepicker 控件的属性。我觉得我的绑定有问题,请您帮忙?
以下是代码。请你告诉我我做错了什么?
<Controls:DatePicker Height="20"
Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="2"
x:Name="dateControl"
IsTodayHighlighted="True"
Margin="5,10,5,20"
SelectedDate="{Binding Path=BindingDate, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
public class Context : INotifyPropertyChanged
{
public Context() { }
private DateTime bindingDate = DateTime.Today;
public DateTime BindingDate
{
get
{
return bindingDate;
}
set
{
if (DateTime.Compare(DateTime.Today, value) < 0)
{
MessageBox.Show("Please Select Today date or older, Should not select future date");
//这在控件的SelectedDate属性中没有任何时候体现,为什么??? 值 = 日期时间。今天; } 绑定日期 = 值; OnPropertyChanged("绑定日期"); } }
..是的,我正在设置窗口的数据上下文,如下所示:
public Window1()
{
InitializeComponent();
this.DataContext = new Context();
}
任何建议都将受到高度赞赏。
谢谢, -迈克
【问题讨论】:
标签: wpf binding wpftoolkit