I have a member in the WPF code behind that is disposable (meaning it implements the IDisposable interface)
I do not see any Dispose method I can override from UserControl in WPF so I can dispose of the member in my wpf usercontrol
What is the correct way to dispose of a member in a WPF usercontrol?
It's a usercontrol that wraps a private member which implements the IDisposable interface. Thus I need to dispose of that member somewhere. In the tradition winform, the usercontrol had a Dispose method that could be overriden so that in the override I could dispose of the private member. But in the WPF usercontrol, there is no such thing. So I was wondering where can I dispose of the private member in the wpf usercontrol.
My question is not about disposing the usercontrol, but where to dispose one of its private member which implement the IDisposable interface
You could use the Unloaded event of the UserControl to do your resource cleanup.
You would do it in the Dispatcher.ShutDownStarted event handler. See this question for details (which in turn refers to this blog post).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With