Graphics Reference
In-Depth Information
a menu bar, buttons, and sliders, as well as a large area in which we can draw
things. The arrangement of these items is determined in the Window1.xaml file:
When you want to add a button to the test bed, you'll edit that file; when you
want to arrange a connection between a slider drag and a certain action in your
program, you'll edit that file, etc.
The Window1.xaml.cs file is concerned almost entirely with creating the con-
tents of the one large area in which we can draw things.
We'll examine both of the Window1 files now. We'll omit large sections of each,
sections that are repetitive or boilerplate, and concentrate on the details that you'll
use as you write your own programs.
A complex XAML file like Window1.xaml (see Listing 4.3) can describe sev-
eral things at once: layout (the positioning of things within the window), event
handling (what happens when you press a keyboard key or click on a button),
styles (the font in which text appears, the color of a button), etc. For now, we'll
concentrate on the layout aspects. Start by examining the code and trying to figure
out what's going on, and we'll explain a few details shortly.
Listing 4.3: The XAML code for the test bed.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<Window
x:Class= "Testbed2D.Window1"
xmlns= "http://schemas.microsoft.com/winfx/2006/ ... "
xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x= "http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:h= "clr-namespace:Testbed2D"
Title= "2D Testbed"
KeyDown= "KeyDownHandler"
Height= "810"
Width= "865"
>
<DockPanel LastChildFill= "True" >
<Menu DockPanel.Dock= "Top" >
<MenuItem Header= "File" >
<MenuItem Header= "New" Background= "Gray" />
<MenuItem Header= "Open" Background= "Gray" ...
</MenuItem>
<MenuItem Header= "Edit" /> ...
</Menu>
<StackPanel DockPanel.Dock = "Left" Orientation= "Vertical" Background= "#ECE9D8" >
<TextBlock Margin= "3" Text= "Controls" />
<Button Margin= "3,5" HorizontalAlignment= "Left" Click= "b1Click" >Next </Button>
<Button Margin= "3,5" HorizontalAlignment= "Left" Click= "b2Click" >Do It </Button>
<Slider Width="100" Value="0" Orientation="Horizontal"
ValueChanged="slider1change" HorizontalAlignment="Left"
IsSnapToTickEnabled="True" Maximum="20" TickFrequency="2"
AutoToolTipPlacement="BottomRight" TickPlacement="BottomRight"
AutoToolTipPrecision="2" IsDirectionReversed="False"
IsMoveToPointEnabled="False"/>
</StackPanel>
<h:GraphPaper x:Name= "Paper" >
</h:GraphPaper>
</DockPanel>
</Window>
First, there are several namespaces involved in this code: We use standard
WPF entities, which are defined in a WPF namespace, as well as entities like
 
 
Search WWH ::




Custom Search