Dom
Dom

Reputation: 40511

Set DatePicker to Today using XAML

I have the following DatePicker control in my project:

<DatePicker x:Name="startDate" SelectedDate="2013-04-03"></DatePicker>

QUESTION:
Is it possible to set the DatePicker.SelectedDate using only XAML?

I know this can be achieved using code-behind.

Upvotes: 6

Views: 5658

Answers (1)

Kevin DiTraglia
Kevin DiTraglia

Reputation: 26078

Try this...

Add this to xaml refs:

xmlns:sys="clr-namespace:System;assembly=mscorlib"

Then write this:

<DatePicker SelectedDate="{x:Static sys:DateTime.Now}"/>

Upvotes: 12

Related Questions