Graphics Reference
In-Depth Information
Figure 4.2: The
Testbed2D
application running. All the things in the large graph-paper
window are drawn by the
Window1.xaml.cs
code and are not described in the XAML file.
comes with a graph-paper-like grid and coordinate axes predrawn, and distances
on a
GraphPaper
are measured in millimeters rather than in WPF units (which
are sized at 1
96 of an inch).
3
We won't examine the entire description of the
GraphPaper
class; we'll just use it. After you've read the next two chapters, it'll be
worth your time to examine the XAML and C# that together define
GraphPaper
.
Down at the bottom of the
Window1
XAML file we create an instance of a
GraphPaper
; to do so, we have to say that it's an
h:GraphPaper
, telling the pro-
gram what namespace to find it in. We also give it a name—
Paper
—by which we
can refer to it within the C# file.
Figure 4.2 shows the appearance of the program when it's run. All the interest-
ing content is generated by the C# code, but the entire appearance of the interface
is determined by the XAML code.
/
The associated C# code (
Window1.xaml.cs
) is also relatively simple (see List-
ing 4.5). There is no fancy software engineering involved; this test bed is meant
to act as the equivalent of a pad of scratch paper, not as a foundation for large
systems. If you plan to build a large application atop WPF, you should get famil-
iar with WPF itself, not the distilled portion of it that we have used for this 2D
test bed.
Recall that we've only
partially
described a
Window1
in the XAML; the C#
file contains the remainder of the definition. Because we're displaying a polygon,
3. There's one exception: If you set your display's dpi setting to something that does not
match the actual number of dots per inch of your physical display, then a WPF unit
will not appear as 1
/
96 of an inch.