Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF drawing performance with large numbers of elements
    primarykey
    data
    text
    <p>I'm trying to create a custom control in WPF to display the game tree for a <a href="http://en.wikipedia.org/wiki/Go_(game)" rel="nofollow noreferrer">game of go</a> (see <a href="http://i46.tinypic.com/ickz11.png" rel="nofollow noreferrer">here</a> for what it looks like). I've more-or-less got it working laying out the nodes, but one problem I've found is that it begins gets noticeably slow to render/navigate (it's in a scroll viewer) when the number of nodes gets larger than about 30. Since an average game of go consists of around 200 moves (not to mention other branches that the player might fork onto), this is going to be a fairly big problem in any realistic game.</p> <p>Currently, I'm using individual user controls for the game nodes (each being an ellipse with a shadow bitmap effect on it and some text annotation) and simple lines for the arcs in the tree, all of which are positioned absolutely in a canvas.</p> <p>The layout algorithm isn't such a problem since this only has to be executed when a new branch is created (otherwise the node can be added directly beneath its parent, so no other nodes need to be relocated). The main problem is simply that any kind of manipulation of this canvas and its elements is very slow, presumably just due to the number of children it has. It obviously gets slower as the width and complexity of the tree increases, since there are more arcs as well as nodes.</p> <p><strong>My question:</strong> What's the proper way to about drawing a large/complex structure like this in such a way that it doesn't render too slowly as it grows?</p> <p><strong>Edit:</strong> This is related to <a href="https://stackoverflow.com/questions/1985542/translatepoint-within-a-canvas">my other question</a>.</p> <p><strong>Edit:</strong> Here's the markup for the user controls I'm using for the nodes:</p> <pre><code>&lt;UserControl x:Class="Go.UI.GameNodeMarker" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Go.UI" xmlns:wpftools="clr-namespace:WpfTools.Extensions;assembly=WpfTools" x:Name="_This"&gt; &lt;UserControl.Resources&gt; &lt;!-- Some brushes, resources, etc. are omitted --&gt; &lt;Style x:Key="StoneStyle" TargetType="{x:Type Ellipse}"&gt; &lt;Setter Property="StrokeThickness" Value="0"/&gt; &lt;Setter Property="BitmapEffect" Value="{StaticResource StoneEffect}"/&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Binding="{Binding ElementName=_This, Path=StoneColour}" Value="Black"&gt; &lt;Setter Property="Fill" Value="{StaticResource BlackStoneBrush}"/&gt; &lt;/DataTrigger&gt; &lt;DataTrigger Binding="{Binding ElementName=_This, Path=StoneColour}" Value="White"&gt; &lt;Setter Property="Fill" Value="{StaticResource WhiteStoneBrush}"/&gt; &lt;/DataTrigger&gt; &lt;DataTrigger Binding="{Binding ElementName=_This, Path=IsEmpty}" Value="True"&gt; &lt;Setter Property="Fill" Value="{StaticResource EmptyBrush}"/&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/UserControl.Resources&gt; &lt;Grid&gt; &lt;Ellipse Style="{StaticResource StoneStyle}"/&gt; &lt;TextBlock Text="{Binding ElementName=_This, Path=Text}" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Medium"/&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>These are being added dynamically to a canvas in order to draw the tree.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload