具有TimeSpanPicker支持的可点击TextBlock

时间:2012-03-09 12:46:20

标签: c# windows-phone-7 customization textblock toolkit

我想实现TimeSpanPicker,但不是以文本框的常用方式实现。我考虑将Textblock设置为可点击,因此如果您单击/点击它,则会显示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()这样的事件。 这有可能吗?

提前致谢!

2 个答案:

答案 0 :(得分:0)

请查看我提供已接受答案的帖子TimePicker without the TextBox

希望它对你有所帮助。

答案 1 :(得分:0)

好的,所以我问了一些人并得到了另一个答案,虽然它不是很优雅。你可以这样做:

在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());
}