Placing elements in exact positions

WPF's layout panels provide much flexibility in building a user interface. Furthermore, most of the panels adapt well to size and content changes of themselves and their child elements. This means that positions and sizes don't necessarily remain the same as the user resizes or otherwise manipulates the UI.

Most of the time that's a good thing; sometimes, however, we need to place elements in exact positions without them moving unexpectedly. This is typical of highly graphical content, such as graphs, charts, or animations. The Canvas panel provides a convenient container for such content.

Getting ready

Make sure Visual Studio is up and running.

How to do it...

We'll create a simple application that hosts a Canvas ...

Get Windows Presentation Foundation 4.5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.