C# 如何在日期选择器中显示当前日期
使用c#和silverlight 我想在datepicker中显示当前日期 控制代码C# 如何在日期选择器中显示当前日期,c#,asp.net,silverlight,silverlight-4.0,C#,Asp.net,Silverlight,Silverlight 4.0,使用c#和silverlight 我想在datepicker中显示当前日期 控制代码 <sdk:DatePicker Name="cAccCreditDate" Margin="10,0,0,0" DisplayDate="12/12/2014" HorizontalAlignment="Left" VerticalAlignment="Center" Width="120" Height
<sdk:DatePicker Name="cAccCreditDate"
Margin="10,0,0,0"
DisplayDate="12/12/2014"
HorizontalAlignment="Left" VerticalAlignment="Center"
Width="120" Height="23" />
如何显示日期,需要代码帮助尝试设置
SelectedDate
值
cAccCreditDate.SelectedDate = DateTime.Now;
我的建议是向DatePicker添加绑定,如下所示:
SelectedDate="{Binding DateToBind, Mode=TwoWay}
然后设置DateToBind的值
UPD:
示例代码(注意:这只是几分钟内创建的示例)
您所说的
不工作是什么意思?
?当前日期不显示Hanks,Datetobind设置值在c#。。?我试着用c#Datetobind DateTime;Datetobind=DateTime.Now,但不显示,如何执行此操作。。
SelectedDate="{Binding DateToBind, Mode=TwoWay}
namespace SilverlightApplication1
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
DataContext = new ViewModel();
}
}
public class ViewModel: INotifyPropertyChanged
{
private DateTime _currentDateTime;
public DateTime CurrentDateTime
{
get { return _currentDateTime; }
set {
_currentDateTime = value;
OnPropertyChanged("CurrentDateTime");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
public ViewModel()
{
CurrentDateTime = DateTime.Now;
}
}
}