Wpf DatePicker 水印修改为中文
Posted 雨田博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 = "选择日期"; }
以上是关于Wpf DatePicker 水印修改为中文的主要内容,如果未能解决你的问题,请参考以下文章