TimePicker without the TextBox

房东的猫 提交于 2019-12-21 21:38:42

问题


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.


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!