支持TimeSpanPicker的可点击文本块
本文关键字:文本 TimeSpanPicker 支持 | 更新日期: 2023-09-27 18:27:11
我想实现TimeSpanPicker,但不是用Textbox的通用方式。我想让一个文本块可以点击,所以如果你点击/点击它,TimeSpanPicker就会出现。我试过这样做,但不起作用:
private void tb_Timer_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
TimeSpan TimeSpanDuration = TimeSpan.FromMilliseconds(status.duration);
TimeSpanPicker timeSpanPicker = new TimeSpanPicker();
timeSpanPicker.Max = new TimeSpan(TimeSpanDuration.Hours, TimeSpanDuration.Minutes, TimeSpanDuration.Seconds);
timeSpanPicker.Step = new TimeSpan(0, 0, 1);
}
我没有通过谷歌找到什么,也没有像show()这样的活动。这在某种程度上可能吗?
提前感谢!
好的,所以我问了一些人,得到了另一个答案,尽管不是很优雅。你可以这样做:
在XAML中:
xmlns:c4fToolkit="clr-namespace:Coding4Fun.Phone.Controls.Toolkit;assembly=Coding4Fun.Phone.Controls.Toolkit"
<c4fToolkit:TimeSpanPicker x:Name="_TimeSpanPicker" Visibility="Collapsed" Width="0" Height="0" ValueChanged="_TimeSpanPicker_ValueChanged" />
<Button x:Name="DateTimeButton" Content="Button" Height="72" HorizontalAlignment="Left" Margin="68,428,0,0" VerticalAlignment="Top" Width="160" Click="DateTimeButton_Click" />
在C#中:
using Coding4Fun.Phone.Controls.Toolkit;
private void DateTimeButton_Click(object sender, RoutedEventArgs e)
{
TimeSpan TimeSpanDuration = TimeSpan.FromMilliseconds(status.duration);
_TimeSpanPicker.Max = new TimeSpan(TimeSpanDuration.Hours, TimeSpanDuration.Minutes, TimeSpanDuration.Seconds);
_TimeSpanPicker.Step = new TimeSpan(0, 0, 1);
_TimeSpanPicker.OpenPicker();
}
private void _TimeSpanPicker_ValueChanged(object sender, ValueChangedEventArgs<TimeSpan> e)
{
MessageBox.Show(_TimeSpanPicker.Value.ToString());
}