You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除WPF Material Design TimePicker的默认提示文本

Fixing the "select time" Placeholder in Material Design TimePicker

Got it, let's sort out that default "select time" prompt in your Material Design TimePicker. Since you're initializing the control in code-behind, here are two simple, effective ways to remove it:

1. Set PlaceholderText to Empty Directly in Code

The quickest fix is to explicitly override the default placeholder text when you initialize the control. Just add one line to your existing code:

control = new MaterialDesignThemes.Wpf.TimePicker 
{ 
    Name = "timepicker_" + df.dataName, 
    SelectedTime = null, 
    HorizontalAlignment = HorizontalAlignment.Center, 
    VerticalAlignment = VerticalAlignment.Center,
    PlaceholderText = string.Empty // This line removes the default prompt
}; 
this.RegisterName("timepicker_" + df.dataName, control);

This works because the Material Design TimePicker exposes the PlaceholderText property directly—setting it to an empty string will overwrite the default "select time" text immediately.

2. Override the Control Style (Fallback Option)

If for some reason the first method doesn't behave as expected (though it should!), you can define a custom style to strip out the placeholder. Add this to your XAML resources:

<Style TargetType="materialDesign:TimePicker">
    <Setter Property="PlaceholderText" Value="{x:Null}" />
    <!-- If you need deeper template changes, you can copy the default control template here and modify the placeholder text block -->
</Style>

That said, the first approach is the most straightforward and should solve your issue without extra complexity. Just drop that line into your code-behind initialization and you're good to go!

内容的提问来源于stack exchange,提问作者Joy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:18:24