fex*_*fex 2 c# xaml windows-runtime
如何在 WinRT 中处置由 XAML 代码创建的控件?我创建了ImageSlideShow
使用SempahoreSlim
and DispatcherTimer
(我使用timer.Tick事件)的UserControl。我应该将 .Unloaded 事件处理程序添加到ImageSlideShow
用户控件或实现 IDisposable (xaml 是否负责调用 .Dispose?)以释放资源和事件处理程序 - 或者我是否需要像在代码隐藏中创建的控件一样手动处理它?
您应该使用Unloaded
的事件UserControl
。在取消所有事件的挂钩中,如果您正在使用任何集合控件,则将<Image />
& 设置ItemsSource
为无效。null
如何使图像无效?
BitmapImage bitmapImage = image.Source as BitmapImage;
bitmapImage.UriSource = null;
image.Source = null;
Run Code Online (Sandbox Code Playgroud)
这image
是对象<Image />
还要实现IDisposable
接口。然后,您需要浏览完整的 UI 元素树,搜索<Image />
并调用Dispose
所有元素。
有关更多信息,请查看此(也适用于 W8):How to debug most common memoryleaks on WP8
归档时间: |
|
查看次数: |
3282 次 |
最近记录: |