ratishphilip / wpfspark

A rich UserControl library to enhance the look and feel of WPF applications.
http://www.codeproject.com/Articles/1060961/WPFSpark-v
MIT License
549 stars 84 forks source link

No Disposing of ToggleSwitch #2

Closed bisato closed 8 years ago

bisato commented 8 years ago

Hello,

the AddValueChanged in the ctor of ToggleSwitch is preventing the disposing of ToggleSwitch. See here. I propose to add this to the ctor:

this.Unloaded += OnUnloaded;

and then add this method:

private void OnUnloaded(object sender, RoutedEventArgs routedEventArgs) { this.Unloaded -= OnUnloaded; // Unlisten to the BorderThickness changed event to update the layout var dpd = DependencyPropertyDescriptor.FromProperty(BorderThicknessProperty, typeof(ToggleSwitch)); dpd?.RemoveValueChanged(this, EventHandler); }

ratishphilip commented 8 years ago

Done. Thank you.