I posted this question at Nov-28 and promised an answer Nov-29. Well, was a bit busy for it, however now it comes
Creation
- 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
- This is the right answer
- 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
- Absolutely unnecessary to use custom control in order to create simple visuals. It's huge overhead.
Movement
- Binding to Canvas.Left/Top X and Y properties forces layout to happen again - we do not want it happened
- This is the right answer
- Creating and removing objects from the source collection, forces full redraw, thus rendering thread will throw and tessellate visuals.
- 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:
Post a Comment