<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.silverlight.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Programming with .NET - General</title><link>http://forums.silverlight.net/forums/17.aspx</link><description>General discussions around authoring Silverlight .NET applications.</description><dc:language>en</dc:language><generator>CommunityServer 2007 (Build: 20416.853)</generator><item><title>Re: Silverlight 2 Post Beta2 Gotcha - Layout Cycle Detected</title><link>http://forums.silverlight.net/forums/thread/97898.aspx</link><pubDate>Fri, 26 Sep 2008 17:20:45 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:97898</guid><dc:creator>avbersSL</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/97898.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=97898</wfw:commentRss><description>&lt;p&gt;Well, I&amp;#39;m getting this error also, but I do not use the layoutupdated event..&lt;/p&gt;
&lt;p&gt;It seems to me it also throws an error when some layout&amp;nbsp;work is taking too long..&lt;/p&gt;
&lt;p&gt;I didn;t do any real investigation, but I&amp;#39;ll report back the next week about this issue I&amp;#39;m seeing..&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Update: I created a video to see the problem.. It shows the problem is related to some timing issue I think...&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.youtube.com/watch?v=P9bL0mqQHgs"&gt;http://www.youtube.com/watch?v=P9bL0mqQHgs&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Silverlight 2 Post Beta2 Gotcha - Layout Cycle Detected</title><link>http://forums.silverlight.net/forums/thread/97879.aspx</link><pubDate>Fri, 26 Sep 2008 16:52:36 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:97879</guid><dc:creator>JeffHandley</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/97879.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=97879</wfw:commentRss><description>&lt;p&gt;Also posted to my blog: &lt;a href="http://blog.jeffhandley.com/archive/2008/09/26/silverlight-2-post-beta2-gotcha---layout-cycle-detected.aspx"&gt;http://blog.jeffhandley.com/archive/2008/09/26/silverlight-2-post-beta2-gotcha---layout-cycle-detected.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I wanted to talk about a common error that people are seeing.&amp;nbsp; This error is something new that you might see when moving code from Beta 2 to the Release Candidate or later.&amp;nbsp; In Beta 2, if the layout engine detected a cycle, it didn&amp;#39;t throw any errors; as I understand it, the layout was just aborted.&amp;nbsp; But with post Beta2 bits, an error is thrown.&lt;/p&gt;
&lt;p&gt;The error you&amp;#39;ll get will specify &amp;quot;Layout Cycle Detected&amp;quot; as the message.&amp;nbsp; This error message is very accurate--the layout engine detected a cycle within your layout; or another way to say it, you have an infinite loop in your layout.&lt;/p&gt;
&lt;p&gt;The biggest culprit that leads to this error is code within the LayoutUpdated event handler.&amp;nbsp; If your LayoutUpdated event handler does anything to alter the layout of your control, then that will cause the LayoutUpdated event to fire again, and again, and again... :-)&lt;/p&gt;
&lt;p&gt;Sometimes you need to have layout altering code within this event handler though, so what is one to do?&lt;/p&gt;
&lt;p&gt;First, you should consider whether you really need the layout changes to occur on every call to LayoutUpdated.&amp;nbsp; Would it suffice to handle the Loaded event as well as the Application.Current.Host.Content.Resized event.&amp;nbsp; Between these two events, you&amp;#39;ll get notified when the control is loaded into the visual tree, and you&amp;#39;ll get notified any time the host is resized, which could cause you to need to change your layout again.&amp;nbsp; Scenarios like modal dialogs should fall into this category.&lt;/p&gt;
&lt;p&gt;Second, if you really do need to use LayoutUpdated, you might just need to put some conditions around your layout changes.&amp;nbsp; For instance, if you are calculating a new width and height for your control, before you actually set the width and height, check to make sure the current values differ from what you calculated.&amp;nbsp; This will allow the first LayoutUpdated event to resize your control, which triggers another LayoutUpdated event, but that event will recognize that there&amp;#39;s no work to do, and the cycle will end.&lt;/p&gt;
&lt;p&gt;These same rules will apply when you&amp;#39;re handling the SizeChanged event, or if you&amp;#39;re doing any other overrides on the layout of your control.&lt;/p&gt;</description></item></channel></rss>