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

如何移除MahApps DateTimePicker控件中的时间部分?

解决MahApps DateTimePicker隐藏时间部分的问题

要移除文本框和弹出窗口中的时间部分,只需给DateTimePicker添加IsDatePickerOnly="True"属性,同时清理不需要的时间相关配置即可,具体修改如下:

修改后的代码

<controls:DateTimePicker x:Name="CreationDate"
                         SelectedDateTime="{Binding CreationDate}"
                         Width="170"
                         Height="40"
                         HorizontalAlignment="Left"
                         VerticalAlignment="Top"
                         Culture="en-US"
                         Focusable="False"
                         controls:TextBoxHelper.Watermark="Creation Date"
                         controls:TextBoxHelper.UseFloatingWatermark="True"
                         SelectedDateFormat="Short"
                         IsDatePickerOnly="True" />

关键说明

  • IsDatePickerOnly="True":这是核心配置,会将控件切换为仅日期选择模式,文本框只显示日期内容,弹出的选择器也会完全隐藏时间选择区域。
  • 移除SelectedTimeFormat="Short":既然不需要时间相关功能,该配置已无意义,移除后代码更简洁。
  • 若需要自定义日期显示格式,可通过SelectedDateTimeStringFormat指定,比如设置为"yyyy-MM-dd"来显示固定格式的日期。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 17:12:41