我只想使用选择器对话框(如下所示)
来自 Windows Phone 的 Silverlight 工具包中包含的 TimePicker 控件。通常此对话框仅在用户单击 TimePicker 控件列表框时出现。
我想完全绕过列表框并在按下按钮时启动选择器对话框。
这是否可能,或者我必须为自己创建一个自定义控件。
最佳答案
创建继承自TimePicker
的类,并使用ClickTemplateButton()
模拟点击行为:
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();
}
}
创建此类时,在xaml中创建CustomPicker
。不要忘记添加xmlns
xmlns:local="clr-namespace:CustomPickerNamespace"
<local:CustomPicker x:Name="customPicker" .../>
然后调用你可以从代码中显示它:
customPicker.ClickTemplateButton()
关于c# - 没有 TextBox 的 TimePicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8847367/