Wednesday, December 05, 2007

WPF quiz #1 answer: Moving rectangles

I posted this question at Nov-28 and promised an answer Nov-29. Well, was a bit busy for it, however now it comes


  1. It's absolutely unnecessary to create DO, with unchangeable data template. You are not going to use different DataTemplate, and your  rectangle is visual model, so in order to create them,  it's better to one of derived classes, that enables visualization. For example UIElement, which is one of simplest visual objects
  2. This is the right answer
  3. UIElement is smaller and simpler, then FrameworkElement. If you do not need additional features, provided by FrameworkElement (for example input, focus, layout, routed event), use UIElement
  4. Absolutely unnecessary to use custom control in order to create simple visuals. It's huge overhead.


  1. Binding to Canvas.Left/Top X and Y properties forces layout to happen again - we do not want it happened
  2. This is the right answer
  3. Creating and removing objects from the source collection, forces full redraw, thus rendering thread will throw and tessellate visuals.
  4. Changing X and Y properties by using  Dispatcher timer (or any other way to do it) will do exactly the same thing, as in 1 - invalidation. We do not want it.

Have a nice day. And keep looking for WPF quiz #2

No comments: