rony
rony

Reputation: 520

My DatePicker doesn't have the SelectedDate properties in wp8

I have problem with toolkit:DatePicker, there isn't SelectedDate Properties. I've tried to put

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

inside the XAML. How am I supposed to solve it. I'm using Windows Phone 8.

<grid>
<toolkit:DatePicker x:Name="datePicker" Foreground="Gray" Header=""  Margin="0,364,10,362" Value="10/10/2010" ValueChanged="datePicker_ValueChanged"/>
</grid>

Upvotes: 0

Views: 921

Answers (2)

stackamar
stackamar

Reputation: 214

By default the WP8 toolkit DatePicker shows current date as selected Date. If you want to set any other date, you can set using value property of DatePicker. If you want to retrieve the selected date, then you can use DataPicker.Value and cast it to your need.

Upvotes: 0

Rohit Vats
Rohit Vats

Reputation: 81243

DateTime.Now is static property so you can bind using x:Static markup extension like this:

<toolkit:DatePicker xmlns:sys="clr-namespace:System;assembly=mscorlib"
                    Value="{x:Static sys:DateTime.Now}"/>

sys corresponds to System namespace where DateTime is declared.


I hope StaticResource exist in WP8. If yes above can be simulate like this as well:

<Grid xmlns:sys="clr-namespace:System;assembly=mscorlib">
  <Grid.Resources>
     <sys:DateTime x:Key="CurrentDateTime"/>
  </Grid.Resources>
  <toolkit:DatePicker Value="{Binding Path=Now,
                        Source={StaticResource CurrentDateTime}, Mode=OneWay}"/>

</Grid>

PS - Define resource anywhere you feel like (I used Grid to depict to declare it somewhere in parent element only).


Last if above doesn't seem to work (ideally it should have), I would suggest to have wrapper property in your DataContext class that will return Today's DateTime and bind with it.

    public DateTime CurrentDateTime
    {
        get
        {
            return DateTime.Now;
        }
    }

and bind directly with it:

<toolkit:DatePicker Value="{Binding Path=CurrentDateTime, Mode=OneWay}"/>

Upvotes: 1

Related Questions