问题
I have button and TimeSpanPicker in XAML.
<Image x:Name="sleepButton" Source="img/Sleep.png"
Grid.Row="2" Grid.Column="2" Grid.ColumnSpan="2"
Stretch="None" Tap="sleepButton_Tap"/>
<controls:TimeSpanPicker x:Name="timespanPicker" Step="0:5" Value="0:0"
PickerPageUri="timePickerPage"
Grid.Column="1" Grid.Row="2"
Visibility="Collapsed" IsEnabled="False" />
And here is my code.
private void sleepButton_Tap(object sender, GestureEventArgs e)
{
TimeSpanPicker timespanPicker = new TimeSpanPicker();
timespanPicker.PickerPageUri = new Uri("/MainPage.xaml", UriKind.Relative);
timespanPicker.OpenPicker();
}
Then I click the button do nothing. What I'm doing wrong?
回答1:
The PickerPageUri is if you have a custom picker control such as a single button to set the date/time, not to show the TimeSpanPicker. You're also creating a new instance of TimeSpanPicker here essentially overriding your xaml:
private void sleepButton_Tap(object sender, GestureEventArgs e)
{
TimeSpanPicker timespanPicker = new TimeSpanPicker();
...
You should just be able to call timespanPicker.OpenPicker();
. Not sure if you'll need to enable it, but yes, have the visibility collapsed.
回答2:
You need to change the PickerPageUri to something other than the MainPage.xaml. The intention is to navigate to another page so that you can use this other page to set the time. The following article should help you with this :-
http://windowsphonegeek.com/articles/WP7-TimeSpanPicker-in-depth
来源:https://stackoverflow.com/questions/10319568/how-to-open-timespanpicker-on-a-button-coding4fun-toolkit