释放动态加载的用户控件 [英] Diposing dynamically loaded user controls

查看:77
本文介绍了释放动态加载的用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在WPF中处置动态加载到基于Windows的应用程序的任何对象.

我使用了一个堆栈面板,将这些控件加载到其中,如下所示:

解决方案



mainStackPanel.Children.Clear()将从堆栈面板的集合中删除其子对象,但是这些对象将一直存在于内存中,除非它们被实际处置.您可以遍历堆栈面板的childs集合中的每个对象,并删除该对象,然后通过对这些控件实现IDisposable接口来手动处理该对象.

希望这会有所帮助.

谢谢,
Ravi Bhatt.


i unable to dispose any of the object dynamically loaded to a windows based application in WPF.

i used a stackpanel into which i load these controls like the following

解决方案

Hi,

mainStackPanel.Children.Clear() will remove the child objects of stack panel from its collection but the objects will be there in memory unless they are actually disposed. You can iterate over each and every object from stack panel's children collection and remove that object and then dispose it manually by implementing IDisposable interface to those controls.

Hope this helps.

Thanks,
Ravi Bhatt.


这篇关于释放动态加载的用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆