如何移除WPF 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

