Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF DatePicker show DateTime.Today OR Binding

What is the best way to have a WPF DatePicker show a predefined DateTime (e.g. DateTime.Today) while still maintaining binding?

SelectedDate="{x:Static sys:DateTime.Today}"

and

Text="{Binding Path=MyPublicProperty.ADateTimeMemberProperty, Mode=TwoWay}"

don't play well together. When a UserControl is loaded, I'd like it to display today's date, until a row is selected. Is there a way to make them get along?

like image 853
Wim Ombelets Avatar asked Jun 18 '13 08:06

Wim Ombelets


1 Answers

Text="{Binding Path=MyPublicProperty.ADateTimeMemberProperty, 
       Mode=TwoWay, FallbackValue={x:Static sys:DateTime.Today}}"

Use FallbackValue to set a value when it cannot be retrieved from the binding.

like image 156
Bas Avatar answered Nov 24 '22 04:11

Bas