I want to use only the chooser dialog (shown below)
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.
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.
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()
来源:https://stackoverflow.com/questions/8847367/timepicker-without-the-textbox