【发布时间】:2010-04-20 17:31:58
【问题描述】:
我的目标是让用户选择一年和一个月。将选择转换为日期并让用户控件将日期发送回我的视图模型。那部分对我有用....但是,我无法获得 ViewModel 的初始日期来设置这些下拉菜单。
public static readonly DependencyProperty Date =
DependencyProperty.Register("ReturnDate", typeof(DateTime), typeof(DatePicker),
new FrameworkPropertyMetadata{BindsTwoWayByDefault = true,});
public DateTime ReturnDate
{
get { return Convert.ToDateTime(GetValue(Date)); }
set
{
SetDropDowns(value);
SetValue(Date, value);
}
}
SetDropDowns(value) 只是设置组合框上的选定项,但是,程序永远不会使用该方法。
在我使用的视图上:
<cc1:DatePicker ReturnDate="{Binding Path=StartDate, Mode=TwoWay}" IsStart="True" />
如果这个问题得到了回答,那我就错了。我环顾四周,没有看到任何对我有用的东西。因此,当程序加载时,我如何从视图模型中获取值到方法中以设置组合框?
谢谢,
-斯科特
【问题讨论】:
标签: c# wpf wpf-controls user-controls dependency-properties