【问题标题】:Layout cycle detected error with two progressRings布局周期检测到两个progressRings 错误
【发布时间】:2015-07-22 10:52:09
【问题描述】:

我想创建一个带有两个网格的自定义用户控件,我想在其中加载图像,并且在加载图像之前,我想显示 progressRing 控件。当我添加第二个 ProgressRing 时会出现问题。我的 XAML 如下所示:

<Grid Margin="0,0,0,21" Background="{ThemeResource PhoneAccentBrush}">

        <Grid x:Name="leftImage" Margin="10" Width="190" Height="190" 
              HorizontalAlignment="Left">
            <Image x:Name="imageHolderLeft" x:FieldModifier="public" Width="180"         
                   Height="180" ImageFailed="imageHolderLeft_ImageFailed" 
                   ImageOpened="imageHolderLeft_ImageOpened"/>
            <Grid>
                <ProgressRing x:Name="waitImageLeft" IsActive="True" 
                              VerticalAlignment="Center" HorizontalAlignment="Center" 
                              Background="Transparent" 
                              Foreground="{ThemeResource AppBarBackgroundThemeBrush}"/>
            </Grid>
        </Grid>

        <Grid x:Name="rightImage" Margin="10" Width="190" Height="190" 
              HorizontalAlignment="Right">
            <Image x:Name="imageHolderRight" x:FieldModifier="public" Width="180" 
                   Height="180" ImageOpened="imageHolderRight_ImageOpened" 
                   ImageFailed="imageHolderRight_ImageFailed"/>
            <Grid>
                <ProgressRing x:Name="waitImageRight" IsActive="True" 
                              VerticalAlignment="Center" HorizontalAlignment="Center" 
                              Background="Transparent" 
                              Foreground="{ThemeResource AppBarBackgroundThemeBrush}"/>
            </Grid>
        </Grid>

    </Grid>

因此,当我注释掉一个 ProgressRing 时,它可以正常工作,但是当其中有两个时,我的程序崩溃并出现以下错误:Layout cycle detected. Layout could not complete

有人知道为什么吗? 谢谢:)

【问题讨论】:

  • 其实你没有提到错误。抛出了哪个异常?
  • 完整错误消息:“检测到布局周期。布局无法完成​​”
  • 你能尝试为所有使用的元素指定一个特定的高度和宽度吗?
  • 做到了。甚至尝试了最大/最小宽度/高度但没有结果
  • 尝试从 中删除 Width="190" Height="190"。网格喜欢拉伸。如果您不希望它拉伸,请使用 StackPanel 或在 Image 和 ProgressRing 控件上设置宽度/高度。

标签: c# xaml user-controls windows-phone-8.1


【解决方案1】:

这个错误表明一个元素的布局依赖于间接依赖于原始元素的其他元素。 Windows 无法弄清楚整体布局......很像无限循环或无限递归。

在您的情况下,原因可能与对齐方式和大小有关。您应该能够通过简化布局来解决问题。保留外部网格,但添加 5 个 ColumnDefinitions,中间一个宽度为 *,另一个宽度为 Auto。摆脱其他 4 个网格。相反,将两个图像和进度环直接放入主 Grid 的第 0、1、3 和 4 列中(使用 Grid.Column 附加属性)。将所需大小放在图像和进度环的 Width 和 Height 属性上,而不是放在 Grid 上。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-23
    • 2016-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-24
    相关资源
    最近更新 更多