如何在WPF中配置UserControl页面 [英] how to dispose usercontrol page in wpf

查看:432
本文介绍了如何在WPF中配置UserControl页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人

如何在wpf中放置usercontrol页面.
通过窗口页面中的Activator.CreateInstance()动态调用的用户控制页面.

Dear all

how to dispose usercontrol page in wpf.
usercontrol page called dynamically through Activator.CreateInstance() in window page.

推荐答案

您无法在WPF中处理页面,或其他很多事情.您必须信任为您执行此操作的框架.
You can''t dispose of pages in WPF, or a lot of other things. You have to trust the framework to do it for you.


所有CLR均基于垃圾收集器(GC).这是托管系统和托管代码的中心思想.

请参阅:
http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29 [ ^ ],
http://en.wikipedia.org/wiki/Garbage_%28computer_science%29 [ ^ ],
http://en.wikipedia.org/wiki/Common_Language_Runtime [ http://msdn.microsoft.com/en-us/library/system.idisposable.aspx [^ ].

此外,某些选定的类的Dispose方法与IDisposable不相关.

另请参见using语句,该语句主要用于(但不是唯一地)用于处理本地(堆栈)一次性对象:沙漏鼠标光标始终更改回原始图像. [ ^ ].)

—SA
All the CLR is based on the Garbage Collector (GC). This is the central idea of managed systems and managed code.

Please see:
http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29[^],
http://en.wikipedia.org/wiki/Garbage_%28computer_science%29[^],
http://en.wikipedia.org/wiki/Common_Language_Runtime[^].

Basically, the objects are destructed and the memory is reclaimed by GC some time after an object looses its reachability, which is not a very trivial concept.

However, there is a provision for user-controlled dispose with is useful for in many cases. A typical case of using disposal is when unmanaged resources are used, but this is not the only case. You need to dispose only the instances of classes or structures implementing the interface System.IDisposable, please see:
http://msdn.microsoft.com/en-us/library/system.idisposable.aspx[^].

Also, some selected classes have their Dispose methods not related to IDisposable.

See also the using statement used mostly (but not exclusively) for handling local (stack) disposable objects: http://msdn.microsoft.com/en-us/library/yh598w02%28v=vs.100%29.aspx[^].

(For an example of the technique not related to disposal, please see my Tips & Tricks article Hourglass Mouse Cursor Always Changes Back to its Original Image. How?[^].)

—SA


这篇关于如何在WPF中配置UserControl页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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