c#uwp检测到Toolkit ImageEx周期

时间:2017-07-28 12:16:46

标签: c# image layout uwp cycle

在UWP中我有这个:

<GridView x:Name="gvList"
        ScrollViewer.HorizontalScrollBarVisibility="Disabled"
        ScrollViewer.HorizontalScrollMode="Disabled"
        ScrollViewer.VerticalScrollBarVisibility="Hidden"
        ScrollViewer.VerticalScrollMode="Enabled"
        VerticalAlignment="Stretch"
        HorizontalAlignment="Stretch"
        ItemTemplate="{StaticResource Template}" 
        Grid.Row="1" 
        ItemContainerStyle="{StaticResource ListViewNoAnimationStyle}">
    <GridView.ItemsPanel>
        <ItemsPanelTemplate>
            <ItemsWrapGrid Orientation="Horizontal"/>
        </ItemsPanelTemplate>
    </GridView.ItemsPanel>
</GridView>

我的datatemplate是这样的:

<DataTemplate x:Key="Template" x:DataType="data:Item">
    <customControls:CustomControl
        Model="{x:Bind Mode=OneWay}"
        Width="{Binding ItemWidth, ElementName=customListControl}" 
        Height="{Binding ItemHeight, ElementName=customListControl}"
        ItemPadding="{Binding ItemPadding, ElementName=customListControl}"/>
</DataTemplate>

在CustomControl中有一个ImageEx控件:

<controls:ImageEx x:Name="imageBackground" Source="{x:Bind Image, Mode=OneWay}" Stretch="UniformToFill"/>

列表中有超过500个项目填充此GridView。

问题是我检测到&#34;布局周期。布局无法完成​​。&#34;错误。如果我使用Image而不是ImageEx,一切都运行正常。

但是,我需要使用ImageEx,因为它会异步设置它的源代码,因此它会在不阻塞UI的情况下填充所有内容。

有人对此有所了解吗?

1 个答案:

答案 0 :(得分:1)

感谢用户AVK和他的链接https://github.com/Microsoft/UWPCommunityToolkit/issues/1328,我已将此样式添加到我的应用程序中,并修复了ImageEx布局循环问题:

<Style TargetType="controls:ImageEx">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="Foreground" Value="{ThemeResource ApplicationForegroundThemeBrush}" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="controls:ImageEx">
                <Grid Background="{TemplateBinding Background}">
                    <Image
                        Name="PlaceholderImage"
                        HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                        VerticalAlignment="{TemplateBinding VerticalAlignment}"
                        Opacity="1.0"
                        Source="{TemplateBinding PlaceholderSource}"
                        Stretch="{TemplateBinding PlaceholderStretch}" />
                    <Image
                        Name="Image"
                        HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                        VerticalAlignment="{TemplateBinding VerticalAlignment}"
                        NineGrid="{TemplateBinding NineGrid}"
                        Opacity="0.0"
                        Stretch="{TemplateBinding Stretch}" />
                    <ProgressRing
                        Name="Progress"
                        Margin="16"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center"
                        Background="Transparent"
                        Foreground="{TemplateBinding Foreground}"
                        IsActive="False"
                        Visibility="Collapsed" />
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Failed">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Image" Storyboard.TargetProperty="Opacity">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="0" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderImage" Storyboard.TargetProperty="Opacity">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="1" />
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Loading">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Progress" Storyboard.TargetProperty="IsActive">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="True" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Progress" Storyboard.TargetProperty="Visibility">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Image" Storyboard.TargetProperty="Opacity">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="0" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderImage" Storyboard.TargetProperty="Opacity">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="1" />
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Loaded">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Progress" Storyboard.TargetProperty="IsActive">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="False" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Progress" Storyboard.TargetProperty="Visibility">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <DoubleAnimation
                                        AutoReverse="False"
                                        BeginTime="0"
                                        Storyboard.TargetName="Image"
                                        Storyboard.TargetProperty="Opacity"
                                        From="0"
                                        To="1" />
                                    <DoubleAnimation
                                        AutoReverse="False"
                                        BeginTime="0"
                                        Storyboard.TargetName="PlaceholderImage"
                                        Storyboard.TargetProperty="Opacity"
                                        From="1"
                                        To="0" />
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Unloaded" />
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>