Reputation: 4945
How to do that? I would like the textbox in the datepicker to show today's date, not by hardcode, perhaps some binding needed?
Upvotes: 3
Views: 4185
Reputation: 18040
try this
<my:DatePicker SelectedDate="{x:Static System:DateTime.Now}" />
Don't forget to add the System namespace
xmlns:System="clr-namespace:System;assembly=mscorlib"
Upvotes: 4
Reputation: 2839
You could always add a DateTime property to your control's code-behind, or to your view model class if you are using one. Just have a property that always returns DateTime.Now (or DateTime.Now.Date, since you don't need the time part) and use that property for your DatePicker.SelectedDate binding.
public DateTime TodaysDate
{
get { return DateTime.Now.Date; }
}
Then in the xaml, assuming the DataContext has been inherited from the parent control, your DatePicker would look something like this...
<DatePicker SelectedDate="{Binding Path=TodaysDate}"/>
Upvotes: 0