WPF: Layout recursion reached allowed limit to avoid stack overflow: '255'

  • Thread starter Thread starter Thorsten Tarrach
  • Start date Start date
T

Thorsten Tarrach

Hi,

I'm binding my Treeview to an XML document that has less than 100 nested Log
nodes. But I still get this error. If the depth of the XML is 100, how can
the visual tree be 255 nodes deep?
The datatemplate for my Treeview looks like this:

<HierarchicalDataTemplate x:Key="LogEntry" DataType="Log"
ItemsSource="{Binding XPath=Log}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding XPath=@Procedure}">
<TextBlock.Foreground>
<SolidColorBrush>
<SolidColorBrush.Color>
<MultiBinding Converter="{StaticResource logcolour}">
<Binding XPath="@Result"/>
</MultiBinding>
</SolidColorBrush.Color>
</SolidColorBrush>
</TextBlock.Foreground>
</TextBlock>
<TextBlock Text=": "/>
<TextBlock Text="{Binding XPath=@ShortText}"/>
</StackPanel>
</HierarchicalDataTemplate>

Thanks, Thorsten
 
Because your tree nodes are composed of their own nested elements. Your
template uses a stack panel. That's one layer. Nested inside you have other
controls that have their own content inside them. That gives you a few
layers. The TreeNode itself will be using one or more containers to hold the
collection of child nodes.

Basically this means that each node is probably comprised of 2 - 5 nested
containers regardless of your data template. If you then nest nodes within
nodes to make it 100 deep, you easily exceed 255 nested visual elements.

Andrew Faust
 
Hello Thorsten,

Nice to see you again! Andrew's explanation is totally right. Thanks for
Andrew's warmhearted discussion! :-)

Each node will be composed of a few nested visuals meaning that the total
number of nested visuals will reach 255 before too long. This is a known
limitation and reported before. WPF has a hardcoded layout recursion limit
something around 250. We can see the layout recursion limitation from
reflector codes as follows,

static ContextLayoutManager()
{
_updateCallback=new
DispatcherOperationCallback(ContextLayoutManager.UpdateLayoutCallback);
_updateLayoutBackground=new
DispatcherOperationCallback(ContextLayoutManager.UpdateLayoutBackground);
s_LayoutRecursionLimit = 250;
}

The product team was also considering improving this limitation. But the
problem is this is a limitation/performance balance issue. So, at this
time, we choose the 250 limitation since it will insure the application
performance. As the performance get improved in the future version. This
limited value will be increased.

You can get a detailed discussion in the following MSDN Forum thread.
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e64aba77-aeb5-4980-
bf37-a37018865b6e/#page:1

Please let me know if there is any future assistance we can provide from
our side. Have a nice day!


Best regards,
Colbert Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks for the explanation Andrew.

Thorsten

Andrew Faust said:
Because your tree nodes are composed of their own nested elements. Your
template uses a stack panel. That's one layer. Nested inside you have
other controls that have their own content inside them. That gives you a
few layers. The TreeNode itself will be using one or more containers to
hold the collection of child nodes.

Basically this means that each node is probably comprised of 2 - 5 nested
containers regardless of your data template. If you then nest nodes within
nodes to make it 100 deep, you easily exceed 255 nested visual elements.

Andrew Faust
 
Back
Top