AttachedProperty.cs 767 B

12345678910111213141516171819202122232425
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. namespace WpfSample {
  4. static class PropADemo {
  5. public static string GetText(DependencyObject obj) {
  6. return (string)obj.GetValue(TextProperty);
  7. }
  8. public static void SetText(DependencyObject obj, string value) {
  9. obj.SetValue(TextProperty, value);
  10. }
  11. public static readonly DependencyProperty TextProperty =
  12. DependencyProperty.RegisterAttached("Text", typeof(string), typeof(PropADemo),
  13. new PropertyMetadata(string.Empty, OnTextChanged));
  14. private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
  15. if (d is Control control) {
  16. }
  17. }
  18. }
  19. }