using System.Windows; using System.Windows.Controls; namespace WpfSample { static class PropADemo { public static string GetText(DependencyObject obj) { return (string)obj.GetValue(TextProperty); } public static void SetText(DependencyObject obj, string value) { obj.SetValue(TextProperty, value); } public static readonly DependencyProperty TextProperty = DependencyProperty.RegisterAttached("Text", typeof(string), typeof(PropADemo), new PropertyMetadata(string.Empty, OnTextChanged)); private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (d is Control control) { } } } }