卸载WPF控件时如何删除附加属性?

卸载WPF控件时如何删除附加属性?,wpf,xaml,attached-properties,Wpf,Xaml,Attached Properties,我有一个AttachedProperty,它绑定到一个singleton 所附财产: public static bool? GetIsFocused(DependencyObject obj) { return (bool?)obj.GetValue(IsFocusedProperty); } public static void SetIsFocused(DependencyObject obj, bool? value) { obj.SetValue(IsFocusedP

我有一个AttachedProperty,它绑定到一个singleton

所附财产:

public static bool? GetIsFocused(DependencyObject obj)
{
    return (bool?)obj.GetValue(IsFocusedProperty);
}

public static void SetIsFocused(DependencyObject obj, bool? value)
{
    obj.SetValue(IsFocusedProperty, value);
}

public static readonly DependencyProperty IsFocusedProperty =
    DependencyProperty.RegisterAttached("IsFocused", typeof(bool?), typeof(FocusExtension), new FrameworkPropertyMetadata(false, OnIsFocusedPropertyChanged) {BindsTwoWayByDefault = true});

private static void OnIsFocusedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    FrameworkElement frameworkElement = (FrameworkElement)d;

    if (e.NewValue is bool boolValue && boolValue)
    {
        //Do some stuff
    }
}
我是这样用的:

<dxe:HyperlinkEdit attachedProperties:FocusExtension.IsFocused="{Binding Source={x:Static configurationFocus:ConfigurationFocusManager.Instance.IsFocus}"
                    Text="SomeText"/>

它工作得很好,但我遇到的一个问题是,即使卸载usercontrol,我仍然会得到触发的
OnIsFocusedPropertyChanged
事件处理程序


当控件被处置或任何类似的操作时,是否有任何方法取消注册

是否从此问题开始尝试?在卸载
HyperlinkEdit
时清除绑定?控件不是一次性的。