I'm writing some WPF custom controls for a third part library. For instance I enhanced the standard ComboBox
with some dependency properties. The main problem is that my controls have as private instances some IDisposable
objects, and I'd like to dispose these objects.
The structure of my controls is something like this :
public class MyComboBox : ComboBox
{
private IDisposableObject _innerObject;
[..]
}
How can I ensure this object is disposed when the control is GC'ed and what is the best way to do that?
Thanks in advance.
P.S.: I tried with the Finalizer
method, but I think that it's not a clean and good solution, and with the Unloaded
event of the control (that it's raised also when the themes changes).