How to open TimeSpanPicker on a Button (Coding4Fun toolkit)

廉价感情. 提交于 2020-01-24 23:57:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!