标签:
效果图:
在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 = "选择日期"; }
标签:
原文地址:http://www.cnblogs.com/yutian/p/5287083.html