Search code examples
win-universal-apptimepickerwindows-10-mobile

Set timepicker value programmatically


I have a timepicker component in my app and I want to set the time with a string I receive from my server. Something like: "12:45" (HH:MM)

My timepicker, in xaml, appears as:

<TimePicker Name="Wake_TimePicker" HorizontalAlignment="Center" Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="1" MaxWidth="90" Margin="0,20,0,0" Header="Wake Hour" />

But I don't know how to change the value it shows when I load my page. I want to show the hour and minutes I got from my server


Solution

  • I think that you can do this with something like this:

    TimeSpan ts = new TimeSpan(serverHour,serverMinutes,0);
    Wake_TimePicker.Time = ts;
    

    You can put this code after InitializeComponent();