Silverlight Layout Cycle Detected
This is an interesting error I ran into while mocking up a page. Turned out it was due to some of the test data I was using, but the result was needing to think if this could happen in the real implementation.
If your working on any controls that might have a large number of textboxes ( > 250) you should read up and pay attention. My search to fix the problem led me to this forum post here. Turns out SL 2 has some interesting behavior that kicks in with greater than 250 textboxes that are visible. Collapsed ones don’t matter only the visible ones…
Way down in the message thread Dave Relyea from Microsoft posted the following key info that explains in more details. He also made it clear this is a high priority bug, however till it’s fixed you should be aware of the behavior.
“Layout uses while loops, and the loops need some sort of upper bound on them so that they don’t loop forever in pathological conditions. An example of a pathological condition is if foo’s size is changed in the foo.SizeChanged event handler. There are a number of ways that a layout loop counter can be “used up” legitimately, such as doing anything to invalidate measure during an arrange call, invalidating measure or arrange during a SizeChanged or LayoutUpdated handler (even if a pathological condition is avoided), etc. The TextBox control is doing something to “use up” a layout loop iteration. Since the layout cycle detection is triggered at 250 iterations, under ideal circumstances, you can measure/arrange at most ~250 TextBoxes at once. It has nothing to do with frame rate, the hardware, the browser, etc. It also doesn’t matter how many TextBoxes you have in total, just how many you are laying out in one frame. This is most critical at startup time, when if you have > 250 visible TextBoxes in the tree, you will get a layout cycle. You will also have problems any other time you add > 250 visible TextBoxes, or if you have somehow incrementally added TextBoxes in groups so that you have gotten away with having more than 250, but all TextBoxes layout has been invalidated at once, such as by resizing the browser. You can have as many collapsed TextBoxes on the screen as you want—layout just skips over collapsed controls. Also, if you add the TextBoxes incrementally, and somehow manage them so that they won’t all get invalidated at once (e.g. by putting them in parent containers that won’t ever be resized) you should be OK.”
Reader Comments