I am building an application in WPF. It consists of a complex background (Canvas containing 3000 rectangles) and five buttons on top of that. The only “Focusable” And “HitVisible” elements are the five buttons. I am having a problem where if I use tab-targeting and focus the last element, there is significant delay between pressing tab and having it focus the first element again. Is there anything I can do without having to remove my background?
for (int i = 0; i < max; ++i)
{
Rectangle rectangle = new Rectangle();
rectangle.Width = 60;
rectangle.Height = 60;
rectangle.Fill = new SolidColorBrush (Color.FromArgb
((byte) random.Next (0, 12), 255, 255, 255));
Canvas.SetLeft (rectangle, x * 30 - 5);
Canvas.SetTop (rectangle, y * 30 - 5);
uiCanvasBackground.Children.Add (rectangle);
}
I would create more lightweight objects such as System.Windows.Media.DrawingVisual objects and draw the rectangle in the drawing context. These would be hosted in a Framework element acting as an ItemsControl.
This great article describes how you could implement an efficient ItemsControl:
Writing More Efficient ItemsControls