Search code examples
c#windows-phone-7customizationtextblocktoolkit

Clickable TextBlock with TimeSpanPicker support


i would like to implement a TimeSpanPicker, but not in the common way with a Textbox. I think about making a Textblock clickable, so if you click/tap on it, the TimeSpanPicker appears. I tried it like this, but this doesn't work:

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

I didn't find something through Google and there is no event like show(). Is this possible in some way?

Thanks in advance!


Solution

  • Ok, so i've asked some people and got and another answer although it isn't very elegant. You can do something like this:

    In 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" />
    

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