Pregunta

I have a TimePicker control from Windows Phone Toolkit placed on my settings page:

<toolkit:TimePicker x:Name="DayStartTimePicker" ValueStringFormat="{}{0:t}"></toolkit:TimePicker>

It works fine until I want to load a previously saved value to it

DayStartTimePicker.Value = SomeDateTimeValue;

After this, I can tap on the control and choose the time, but after confirming it the field's value remains unchanged (it has the SomeDateTime time, but not the one I selected).

I guess I'm missing something, but I couldn't find anything on the internet to fix that issue.

¿Fue útil?

Solución

In your scenario, DayStartTimePicker.Value = SomeDateTimeValue; is called in Loaded event, which calls every time page opens, i.e. whenTimePicker is closed and execution comes back to this page, so selected value is overwrites by old one. You must set default value in page constructor:

// page constructor
Dispatcher.BeginInvoke(() =>
{
    // will be called in first frame render, i.e when page is loaded and builded
    DayStartTimePicker.Value = SomeDateTimeValue;
});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top