Any way to un-register a WPF dependency property?

后端 未结 6 1281
天命终不由人
天命终不由人 2020-12-16 20:14

I\'m running into an unusual problem in my unit tests. The class I\'m testing creates a dependency property dynamically at runtime and the type of that dependency property c

6条回答
  •  星月不相逢
    2020-12-16 20:26

    Had an issue with a ContentPresenter with different Datatemplates where one of them had a DependencyProperty with a PropertyChangedCallback When changing ContentPresenters content to another DataTemplate the callback remained.

    In the UserControls Unloaded event i called:

    BindingOperations.ClearAllBindings(this);
    Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, new DispatcherOperationCallback(delegate { return null; }), null);
    

    That worked for me

提交回复
热议问题