2017-07-28 100 views
0

在UWP我有這樣的:C#UWP工具包ImageEx週期檢測

<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。

問題是我得到了「檢測到佈局週期,佈局無法完成​​」。錯誤。如果我使用圖像而不是ImageEx,則一切正常。

但是,我需要使用ImageEx,因爲它設置它的來源是異步的,所以它填充所有內容而不會阻塞UI。

任何人都有這個想法?

+0

這是一個非常通用的錯誤通常不利於許多。你可以創建一個回購? –

+0

這裏是上傳的項目https://files.fm/u/6ceennzx – user3239349

+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> 
+0

你應該接受它作爲答案! –

+0

我仍然不能接受,還有7個小時。 – user3239349