检测到布局周期错误Windows 8.1 Gridview

时间:2014-06-11 16:04:33

标签: gridview prism windows-8.1 virtualization

我目前正在我的项目中使用Prism WinRT。

基于网络搜索,这是我尝试过的:

  1. 从数据模板中删除了进度条,(这应该已在Win 8.1中修复)
  2. 为图片添加固定宽度和高度
  3. 我发现Progress Bar有这个bug,我把它从我的数据模板中删除了,但我仍然看到了这个bug。

    在初始加载时一切似乎都很好,但是当我根据用户选择的过滤器更改视图模型中的数据集合,并开始滚动时我会间歇性地点击此问题。在让用户滚动之前,我是否应该等待任何事件。

    如果我使用stackPanel作为ItemsPanel,那么我不会看到这个错误,但随后我放弃了虚拟化功能,显示大型数据集需要永远。

    我已经在应用程序中显示了代码,如果有人想要,我可以简化它。

        <SemanticZoom.ZoomedInView>
            <GridView Style="{StaticResource mainGridViewStyle}" ItemsSource="{Binding Source={StaticResource itemsViewSource}}" Name="itemsGridView" common:GridViewItemClickedCommand.Command="{Binding ItemClickedCommand}"  />
        </SemanticZoom.ZoomedInView>
    
        <CollectionViewSource
                x:Name="itemsViewSource"
                Source="{Binding PageData}"
                IsSourceGrouped="True"
                ItemsPath="Contents"
                />
    
        <Style x:Key="mainGridViewStyle" TargetType="GridView">
            <Setter Property="AutomationProperties.AutomationId" Value="ItemsGridView"/>
            <Setter Property="AutomationProperties.Name" Value="Items"/>
            <Setter Property="TabIndex" Value="1"/>
            <Setter Property="Padding" Value="120,0,0,50"/>
            <Setter Property="SelectionMode" Value="Multiple"/>
            <Setter Property="IsSwipeEnabled" Value="True"/>
            <Setter Property="IsItemClickEnabled" Value="True"/>
            <Setter Property="IsEnabled" Value="{Binding IsGridViewEnabled}"/>
            <Setter Property="CanReorderItems" Value="False"/>
            <Setter Property="CanDragItems" Value="False"/>
            <Setter Property="Margin" Value="0"/>
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            <Setter Property="VerticalContentAlignment" Value="Stretch"/>
            <Setter Property="ShowsScrollingPlaceholders" Value="True"/>
            <Setter Property="ItemTemplateSelector" Value="{StaticResource    gridViewTemplateSelector}"/>
    
            <Setter Property="ScrollViewer.IsHorizontalScrollChainingEnabled" Value="False"/>
            <Setter Property="GroupStyleSelector" Value="{StaticResource GridViewGroupStyleSelector}"/>    
            <Setter Property="ItemsPanel">
                <Setter.Value>
                <ItemsPanelTemplate>
                        <ItemsWrapGrid GroupPadding="0,0,80,0" />
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Grid.Row" Value="1"/>
        </Style>
    
         <views:ViewTemplateSelector x:Key="gridViewTemplateSelector" 
                                    iconViewTemplate="{StaticResource iconViewTemplate}"
                                    thumbnailViewTemplate="{StaticResource thumbnailViewTemplate}"/>
    
    
    
         <DataTemplate x:Key="iconViewTemplate">
            <Grid x:Name="itemMainGrid" HorizontalAlignment="Left" Width="200" Height="75" Background="White" Margin="0,0,5,5">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="75"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="90*"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <ProgressRing x:Name="contentUpdatingProgressBar" Grid.RowSpan="3" Grid.ColumnSpan="2" Opacity="0.5" IsActive="{Binding IsContentUpdating}" Foreground="{StaticResource AppHeaderForeGroundColor}" Visibility="{Binding IsContentUpdating, Converter={StaticResource VisibilityConvertor}}">
    
                </ProgressRing>
                <Image x:Name="iconImage" Source="{Binding FileIconLink}" Stretch="UniformToFill"  Grid.RowSpan="3" Margin="5" Width='75" Height ="75">
                    <interactivity:Interaction.Behaviors>
                        <core:EventTriggerBehavior EventName="ImageFailed">
                            <core:ChangePropertyAction PropertyName="Source" Value="{Binding FileIconLink}"/>
                        </core:EventTriggerBehavior>
    
                    </interactivity:Interaction.Behaviors>
                </Image>
    
                <TextBlock x:Name="contentName" Text="{Binding Name}" Margin="2" Style="{StaticResource CaptionTextBlockStyle}" Foreground="Black" Grid.Column="1" HorizontalAlignment="Left">
    
                </TextBlock>
                <TextBlock x:Name="contentSize" Text="{Binding FormattedSize,TargetNullValue=''}" Style="{StaticResource CaptionTextBlockStyle}" Foreground="Black" Margin="2" Grid.Column="1" Grid.Row="1" Visibility="{Binding FormattedSize, Converter={StaticResource SizeVisibilityConvertor}}" HorizontalAlignment="Right" VerticalAlignment="Bottom">
    
                </TextBlock>
    
                <StackPanel x:Name="transferStatusPanel" Grid.Row="2" Grid.Column="1" Orientation="Horizontal"  >
                    <TextBlock Text="{Binding ContentStatus}" FontFamily="Segoe UI" FontWeight="Light" FontSize="8" Margin="2,0,2,0" Foreground="Black" Visibility="{Binding ContentStatus, Converter={StaticResource SizeVisibilityConvertor}}" HorizontalAlignment="Left">
                    </TextBlock>
                    <TextBlock Text="{Binding TransferProgress}" FontFamily="Segoe UI" FontWeight="Light" FontSize="8" Margin="2,0,1,0" Foreground="Black" Visibility="{Binding IsTransferActive, Converter={StaticResource VisibilityConvertor}}" HorizontalAlignment="Left">
                    </TextBlock>
                    <TextBlock Text=" %" FontFamily="Segoe UI" FontWeight="Light" FontSize="8" Margin="0,0,2,0" Foreground="Black" Visibility="{Binding IsTransferActive, Converter={StaticResource VisibilityConvertor}}" HorizontalAlignment="Left">
                    </TextBlock>
                    <!--ProgressBar Visibility="{Binding IsTransferActive, Converter={StaticResource VisibilityConvertor}}" Margin="2" Value="{Binding TransferProgress, FallbackValue=0}" Foreground="Blue" Background="Gray" FlowDirection="LeftToRight"/-->
    
                </StackPanel>
    
            </Grid>
    
        </DataTemplate>
    
        <DataTemplate x:Key="thumbnailViewTemplate">
            <Grid x:Name="itemMainGrid" HorizontalAlignment="Left" Width="150" Height="150" Margin="0,0,5,5">
                <Border Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}">
                    <Image x:Name="iconImage" Source="{Binding ThumbnailLink}" Stretch="UniformToFill" Width='150" Height ="150">
                        <interactivity:Interaction.Behaviors>
                            <core:EventTriggerBehavior EventName="ImageFailed">
                                <core:ChangePropertyAction PropertyName="Source" Value="{Binding FileIconLink}"/>
                            </core:EventTriggerBehavior>
    
    
                        </interactivity:Interaction.Behaviors>
                    </Image>
                </Border>
    
                <StackPanel VerticalAlignment="Bottom" Background="{ThemeResource ListViewItemOverlayBackgroundThemeBrush}">
    
                    <ProgressRing x:Name="contentUpdatingProgressBar" Grid.ColumnSpan="2" Grid.RowSpan="4" IsActive="{Binding IsContentUpdating}" Foreground="{StaticResource AppHeaderForeGroundColor}" Visibility="{Binding IsContentUpdating, Converter={StaticResource VisibilityConvertor}}">
    
                    </ProgressRing>
                    <TextBlock x:Name="contentName" Text="{Binding Name}" Foreground="{ThemeResource ListViewItemOverlayForegroundThemeBrush}" Style="{StaticResource CaptionTextBlockStyle}" Margin="15,0,15,0">
    
    
                    </TextBlock>
                    <TextBlock x:Name="contentSize" Text="{Binding FormattedSize,TargetNullValue=''}" Foreground="{ThemeResource ListViewItemOverlaySecondaryForegroundThemeBrush}" Style="{StaticResource CaptionTextBlockStyle}" TextWrapping="NoWrap" Margin="15,0,15,10" HorizontalAlignment="Right" VerticalAlignment="Bottom">
    
    
                    </TextBlock>
                    <StackPanel x:Name="transferStatusPanel" Orientation="Horizontal"  >
                        <TextBlock Text="{Binding ContentStatus}" FontFamily="Segoe UI" FontWeight="Light" FontSize="8" Margin="2,0,2,0" Foreground="Black" Visibility="{Binding ContentStatus, Converter={StaticResource SizeVisibilityConvertor}}" HorizontalAlignment="Left">
                        </TextBlock>
                        <TextBlock Text="{Binding TransferProgress}" FontFamily="Segoe UI" FontWeight="Light" FontSize="8" Margin="2,0,1,0" Foreground="Black" Visibility="{Binding IsTransferActive, Converter={StaticResource VisibilityConvertor}}" HorizontalAlignment="Left">
                        </TextBlock>
                        <TextBlock Text=" %" FontFamily="Segoe UI" FontWeight="Light" FontSize="8" Margin="0,0,2,0" Foreground="Black" Visibility="{Binding IsTransferActive, Converter={StaticResource VisibilityConvertor}}" HorizontalAlignment="Left">
                        </TextBlock>
                        <!--ProgressBar Visibility="{Binding IsTransferActive, Converter={StaticResource VisibilityConvertor}}" Margin="2" Value="{Binding TransferProgress, FallbackValue=0}" Foreground="Blue" Background="Gray" FlowDirection="LeftToRight"/-->
    
                    </StackPanel>
    
            </Grid>
        </DataTemplate> 
    
        <GroupStyle x:Key="gridViewGroupStyle" HidesIfEmpty="True">
            <GroupStyle.HeaderTemplate>
                <DataTemplate>
                    <Grid x:Name="headerGrid">
                        <Button x:Name="headerButton" Content='{Binding Name}' Background="Transparent" Foreground="AliceBlue" Margin="0" Padding="0,5,5,5" BorderThickness="0" Command="{Binding DataContext.HeaderCommand, ElementName=pageRoot}"
                                               IsRightTapEnabled="False" IsHoldingEnabled="False" IsDoubleTapEnabled="False" CommandParameter="{Binding HeaderIdentifier}" FontFamily="Global User Interface" />
                    </Grid>
                </DataTemplate>
            </GroupStyle.HeaderTemplate>
        </GroupStyle>
    
    
    
    
    
        public class ViewTemplateSelector: DataTemplateSelector
        {
            public DataTemplate iconViewTemplate { get; set; }
            public DataTemplate thumbnailViewTemplate { get; set; }
    
            protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
            {
                if (Utilities.GridviewItemStyle == GridviewItemStyle.IconStyle)
                    return iconViewTemplate;
                else
                    return thumbnailViewTemplate;
    
            }
        }
    
    
        public class GridViewGroupStyleSelector : GroupStyleSelector
        {
            protected override GroupStyle SelectGroupStyleCore(object group, uint level)
            {
                return (GroupStyle)App.Current.Resources["gridViewGroupStyle"];
            }
        }
    

1 个答案:

答案 0 :(得分:1)

所以我无法解决这个问题,但是使用不同的参数再次导航到同一页面(我调整了框架日志以不将这些条目添加到导航历史记录中)解决了这个问题。回收ui元素的某个地方正在引发一个循环。