问题描述
我在 XAML 中有按钮和 TimeSpanPicker.
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" />
这是我的代码.
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?
推荐答案
PickerPageUri 是如果您有自定义选择器控件(例如用于设置日期/时间的单个按钮,而不是显示 TimeSpanPicker).您还在这里创建了一个新的 TimeSpanPicker 实例,基本上覆盖了您的 xaml:
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();
...
您应该能够调用 timespanPicker.OpenPicker();
.不确定您是否需要启用它,但是是的,将可见性折叠起来.
You should just be able to call timespanPicker.OpenPicker();
. Not sure if you'll need to enable it, but yes, have the visibility collapsed.
这篇关于如何在按钮上打开 TimeSpanPicker(Coding4Fun 工具包)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!