【发布时间】: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