zoukankan      html  css  js  c++  java
  • 自定义 日期格式的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();
            }    
        }
  • 相关阅读:
    Json 格式 不能加注释
    优雅是的使用Lambda .map函数
    Tomcat-redis-solr-zookeeper启动命令
    今日静态页面集成
    JMS
    freemarker模板引擎技术
    vscode----vue模板--用户代码片段--快捷
    js求总页数:总条数,每页条数
    新建vue项目
    大数据可视化之---echarts地图组件
  • 原文地址:https://www.cnblogs.com/FaDeKongJian/p/2923052.html
Copyright © 2011-2022 走看看