The WPF control WindowsFormsHost inherits from IDisposable.
If I have a complex WPF visual tree containing some of the above controls what event or method can I use to call IDispose during shutdown?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Building from Todd’s answer I came up with this generic solution for any WPF control that is hosted by a Window and want’s to guarantee disposal when that window is closed.
(Obviously if you can avoid inheriting from IDisposable do, but sometimes you just can’t)
Dispose is called when the the first parent window in the hierarchy is closed.
(Possible improvement – change the event handling to use the weak pattern)