DateTimePicker:如何删除“时间”部分?

问题描述 投票:0回答:1

我在 MahApps 中有一个通用的 DateTimePicker 控件:

<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"
                         SelectedTimeFormat="Short" />

但是我无法隐藏时间(无论是在文本框上,还是在单击图标时打开的弹出窗口上。

如何删除它?

c# wpf mahapps.metro
1个回答
0
投票

该控件不支持。但您可以从中创建自定义控件并覆盖

GetValueForTextBox
方法

public class CustomDateTimePicker : DateTimePicker
{
    protected override string GetValueForTextBox()
    {
        return SelectedDate?.ToString("yyyy-MM-dd");
    }
}

在 XAML 中

<local:CustomDateTimePicker />
© www.soinside.com 2019 - 2024. All rights reserved.