为建立中文知识库加块砖 ——中科大胡不归
问题描述
When navigating from a WPF page with Bing Maps Control for WPF I get the following exception message: "Cannot be disposed while still in the visual tree".
问题分析
一种直接的办法是了解Page的生命周期,在Loaded
和Unloaded
阶段动态添加、移除Map对象。
实际没有解决此问题,可能是我不会处理移除Map完成后的事件CallBack。
好在StackOverflow上有人给出了其他间接的解决办法。
解决方法
在Page对象中添加KeepAlive="True"
使Page不会被Dispose()
可以避免此问题:
<ui:Page x:Class="*.*.OverviewPage"
*
*
mc:Ignorable="d"
d:DesignHeight="720" d:DesignWidth="1080"
KeepAlive="True">