Windows Phone C#: “Layout cycle detected. Layout could not complete.” on LongListSelector Fix

Came across a very weird problem today that has occurred on my application Steam Live which I’ve never come across before…

On a certain Steam Profile I’d get a crash with the following message: “Layout cycle detected.  Layout could not complete.”

After a lot of searching, confusion and everything else I’ve managed to find a fix which I have no idea why it works.

Fix:

Changing the font size of one of my TextBlocks from 21 to any other value.

Finding the problem:

I’ve had a look around at it appears a lot of other people have had problems with the LongListSelector. In future I will be avoiding it as it is clearly buggy and has weird things going on.

My method for finding the problem was to incrementally remove XAML controls from my LongListSelector until it started working. Once I removed the right one it was a case of seeing what was different about it from the others.

Entire XAML:

<phone:LongListSelector x:Name="OwnedGameListBox" Tap="OwnedGameListBoxTap" ScrollViewer.VerticalScrollBarVisibility="Disabled" ItemRealized="OwnedGameListBox_ItemRealized" ItemUnrealized="OwnedGameListBox_ItemUnrealized" BorderThickness="0,20,0,0"  >
    <phone:LongListSelector.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Vertical" Tap="OwnedGameListBoxTap" Margin="0,0,0,12">
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,0,0" Tap="StackPanel_Tap_1">
                    <Image Width="60" Source="{Binding getSmallImageActualURL}" Height="60"  Margin="3" VerticalAlignment="Top" />
                    <StackPanel Margin="15,0,0,0">
                        <TextBlock Width="320" TextWrapping="Wrap" Text="{Binding name}" Margin="0,0,0,0" FontSize="32" />
                        <TextBlock Text="{Binding getTotalPlaytimeFormatted}" Margin="0,0,0,0" TextWrapping="Wrap" FontSize="21" >
                            <TextBlock.Foreground>
                                <SolidColorBrush Color="{StaticResource PhoneAccentColor}"/>
                            </TextBlock.Foreground>
                        </TextBlock>
                    </StackPanel>
                </StackPanel>
            </StackPanel>
        </DataTemplate>
    </phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>

Fixed:

<TextBlock Text="{Binding getTotalPlaytimeFormatted}" Margin="0,0,0,0" TextWrapping="Wrap" FontSize="20" >

 

 

3 responses to “Windows Phone C#: “Layout cycle detected. Layout could not complete.” on LongListSelector Fix”

  1. Definitely giving pub774 a shot again. Had some okay wins using them a bit ago. Worth checking out for the potential. Go and find out at pub774

  2. Hey, I’ve been checking out rss99game lately and it’s pretty cool. The games load fast and they’ve got a decent selection. Definitely worth a look if you’re looking for something new online. Check it out at rss99game

  3. Yo, vando88 is where it’s at. Good odds and a nice variety of options. Been having some fun there, check out vando88 if you’re looking to spice things up.

Leave a Reply

Your email address will not be published. Required fields are marked *