Kiang Teng
Kiang Teng

Reputation: 1705

TimePicker without the TextBox

I want to use only the chooser dialog (shown below)

enter image description here

from the TimePicker control included in the Silverlight Toolkit for Windows Phone. Normally this dialog only appears when a user clicks on the TimePicker control listbox.

enter image description here

I would like to bypass the listbox altogether and launch the chooser dialog when a button is pressed.

Is this possible or would I have to create a custom control for myself.

Upvotes: 2

Views: 849

Answers (1)

Ku6opr
Ku6opr

Reputation: 8126

Create class that inherited from TimePicker, and use ClickTemplateButton() to simulate click behavior:

public class CustomPicker : TimePicker
{
    public void ClickTemplateButton()
    {
        Button button = (GetTemplateChild("DateTimeButton") as Button);
        ButtonAutomationPeer peer = new ButtonAutomationPeer(button);
        IInvokeProvider provider = (peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider);

        provider.Invoke();
    } 
}

When this class is created, create CustomPicker in xaml. Don't forget to add xmlns

 xmlns:local="clr-namespace:CustomPickerNamespace"


 <local:CustomPicker x:Name="customPicker" .../>

And then call you can show it from code:

 customPicker.ClickTemplateButton()

Upvotes: 4

Related Questions