I personally would just assign DateTime.Now
to the AvailableFrom
property in the ViewModel code.
If you want to use XAML though, one option is to make the AvailableFrom
property a DateTime?
(nullable DateTime) rather than a DateTime
. Then the default value is null rather than "01/01/0001".
Then, in your XAML you can use
xmlns:System="clr-namespace:System;assembly=mscorlib"
<DatePicker
HorizontalAlignment="Left"
SelectedDate="{Binding
Path=AvailableFrom,
Mode=TwoWay,
TargetNullValue={x:Static System:DateTime.Now}}"
Margin="139,58,0,0"
VerticalAlignment="Top"
Width="120" />
and the UI will display the current date anytime that AvailableFrom
is null.