繁体   English   中英

MahApps DateTimePicker自定义日期时间格式

[英]MahApps DateTimePicker custom datetime format

我正在使用MahAppsDateTimePicker控件。

<controls:DateTimePicker 
    SelectedDate="{Binding SelectedDateTime, RelativeSource={RelativeSource AncestorType=UserControl}}" 
    SelectedTimeFormat="Short" 
    SelectedDateFormat="Short"
    Culture="en-In"/>

目前它以dd-mm-yyyy HH:mm格式显示日期时间,但我需要以yyyy-mm-dd HH:mm Z格式显示日期时间。 我现在看到它没有将日期时间格式作为字符串模式的属性。 那么该怎么做呢?

是的,该控件不支持此功能。 您可以重写GetValueForTextBox方法来实现此目的

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

XAML

<local:MyDateTimePicker />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM