zoukankan      html  css  js  c++  java
  • Wpf DatePicker 水印修改为中文

    效果图:

    在App.cs添加如下代码:

            protected override void OnStartup(StartupEventArgs e)
            {
                base.OnStartup(e);
                EventManager.RegisterClassHandler(typeof(DatePicker),
                    DatePicker.LoadedEvent,
                    new RoutedEventHandler(DatePicker_Loaded));
            }
    
    
            public static T GetChildOfType<T>(DependencyObject depObj) where T : DependencyObject
            {
                if (depObj == null) return null;
    
                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
                {
                    var child = VisualTreeHelper.GetChild(depObj, i);
    
                    var result = (child as T) ?? GetChildOfType<T>(child);
                    if (result != null) return result;
                }
                return null;
            }
    
            void DatePicker_Loaded(object sender, RoutedEventArgs e)
            {
                var dp = sender as DatePicker;
                if (dp == null) return;
    
                var tb = GetChildOfType<DatePickerTextBox>(dp);
                if (tb == null) return;
    
                var wm = tb.Template.FindName("PART_Watermark", tb) as ContentControl;
                if (wm == null) return;
    
                wm.Content = "选择日期";
            }
  • 相关阅读:
    表单
    超链接
    图像
    表格
    排列清单控制标
    HTML基本结构
    如何快速查看网页源代码
    TOR的使用
    google搜索新姿势
    [NOIP2017]列队
  • 原文地址:https://www.cnblogs.com/yutian/p/5287083.html
Copyright © 2011-2022 走看看