• 自定义 日期格式的datePicker


    用法如下:

    CustomDateFormat 只要是符合日期格式的都可以。如果乱写。就会显示有问题

    <CustomControl:CustomDatePicker Margin="0,100,0,0"  CustomDateFormat="MM/dd/yyyy"/>

    代码如下

    View Code
    public class CustomDatePicker : DatePicker
        {
            public string CustomDateFormat
            {
                get { return (string)GetValue(CustomDateFormatProperty); }
                set { SetValue(CustomDateFormatProperty, value); }
            }
    
            // Using a DependencyProperty as the backing store for CustomDateFormat.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty CustomDateFormatProperty =
                DependencyProperty.Register("CustomDateFormat", typeof(string), typeof(CustomDatePicker), new UIPropertyMetadata(string.Empty,new PropertyChangedCallback(OnCustomDateFormatChanged)));
           
            private static void OnCustomDateFormatChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                Thread.CurrentThread.CurrentCulture = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
                Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = e.NewValue.ToString();
                Thread.CurrentThread.CurrentCulture.DateTimeFormat.LongDatePattern = e.NewValue.ToString();
            }    
        }
  • 相关阅读:
    局域网内其他机器访问本机80网站失败记录
    百度经纬度获取
    Win10安装安卓ADB驱动
    SQL Server 查看数据库是否存在阻塞
    IP地址接口小结
    雄冠条码PV系统-2016-05-17-收获
    slf4j MDC使用
    Java NIO之通道
    Java NIO之缓冲区
    记一次ThreadPoolExecutor面试
  • 原文地址:https://www.cnblogs.com/FaDeKongJian/p/2923052.html
Copyright © 2020-2023  润新知