user3730360
user3730360

Reputation: 11

How to set the default text to DatePicker in windows phone 8 app

How to set the default text to DatePicker?

I searched in many blogs, all are saying to customize the DatePicker. is it not possible to set the string value to default DatePicker?

Upvotes: 0

Views: 1437

Answers (2)

I think there are two solutions:

1) Overlay your DatePicker With a Button and Display the default content inside the button. Basicaly you need to implement next behaviour:

  • When Button is Visible hide DatePicker (By default)
  • When User clicks the button show the DatePicker DateSelector Windows
  • When User chooses value in DateSelector Hide the Button and Display DatePicker

2) Use Telerik RadDateSelector control. You must implement the same behaviour but it is much easier:

  • You have a button with custom content.
  • When user clicks the button show RadDateSelector
  • When user chooses value in RadDateSelector you just set the content of the button to selected value

I use the second approach in my WP8 app and first approach in my WP8.1 app (just because there is no Telerik RadDateSelector for WP8.1 right now).

Hope this helps.

Upvotes: 1

Prasanna Aarthi
Prasanna Aarthi

Reputation: 3453

If you need to set a value for date picker , here is what you need to do

private void DatePicker_Loaded(object sender, RoutedEventArgs e)
{
    DatePicker picker = sender as DatePicker;
    DateTimeOffset newDate = DateTimeOffset.Now;
    DateTimeOffset.TryParse("4/17/2013", out newDate);

    if (picker != null)
    {
        picker.Date = newDate;
        picker.MinYear = DateTimeOffset.Now;
    }
}

Upvotes: 1

Related Questions