Windows phone 8.1 启用NavigationCache和IncrementalUpdateBehavior时,ListViewItems将变为空白
这是我的密码:Windows phone 8.1 启用NavigationCache和IncrementalUpdateBehavior时,ListViewItems将变为空白,windows-phone-8.1,Windows Phone 8.1,这是我的密码: <ListView ItemsSource="{Binding Items}" IsItemClickEnabled="True" ItemClick="ItemView_ItemClick" ContinuumNavigationTransitionInfo.ExitElementContainer="True"> <ListView.ItemTemplate> <DataTemplate> &
<ListView ItemsSource="{Binding Items}" IsItemClickEnabled="True" ItemClick="ItemView_ItemClick" ContinuumNavigationTransitionInfo.ExitElementContainer="True">
<ListView.ItemTemplate>
<DataTemplate>
<Border BorderBrush="{StaticResource ButtonBorderThemeBrush}" BorderThickness="0,0,0,3">
<StackPanel Margin="0,0,0,9.5">
<TextBlock
Text="{Binding Title}"
TextWrapping="Wrap"
Pivot.SlideInAnimationGroup="1"
CommonNavigationTransitionInfo.IsStaggerElement="True"
Style="{ThemeResource ListViewItemTextBlockStyle}"
Margin="0,0,19,0">
<interactivity:Interaction.Behaviors>
<core:IncrementalUpdateBehavior Phase="1"/>
</interactivity:Interaction.Behaviors>
</TextBlock>
<TextBlock
Text="{Binding Description}"
TextWrapping="WrapWholeWords"
Pivot.SlideInAnimationGroup="2"
CommonNavigationTransitionInfo.IsStaggerElement="True"
Style="{ThemeResource ListViewItemContentTextBlockStyle}"
Margin="0,0,19,0">
<interactivity:Interaction.Behaviors>
<core:IncrementalUpdateBehavior Phase="2"/>
</interactivity:Interaction.Behaviors>
</TextBlock>
</StackPanel>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
然后,我在代码隐藏中设置了NavigationCacheMode=NavigationCacheMode.Required
。当我导航到ItemPage并返回时。滑动ListViewItems时,它将变为空白,不再显示。它们就这样消失了:
最后,我找到了问题所在。这是一只虫子 因为在IncrementalUpdateBehavior中,它使用一个名为“FindContentTemplateRoot”的函数在可视化树中搜索关联对象的ContentTemplateRoot。当我导航到另一个页面时,它会引发关联对象的卸载事件并再次搜索可视化树。但这次它失败了,因为它已卸载。VisualTreeHelper.GetParent()返回null
因此,它会导致一个错误,即这种行为通常无法解除关联对象的缓存。当页面返回时,关联的对象将再次缓存。这样关联对象的不透明度和DataContext将设置两次或更多。这简直是一团糟。更多相关讨论可在此处找到: