08.01.2015 Views

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

390<br />

CHAPTER 16 ■ PROGRAMMING SILVERLIGHT WITH XAML AND JAVASCRIPT<br />

The Rectangle<br />

This shape is used to draw a closed, straight-edged shape. As with the Ellipse, you control<br />

its dimensions with its Height <strong>and</strong> Width properties. For example, you can create a<br />

square with XAML like this:<br />

<br />

You can round off the corners of a rectangle with the RadiusX <strong>and</strong> RadiusY properties.<br />

These take a double value specifying the radius of the circle that is used to round the corner.<br />

For example, to change the preceding rectangle to have rounded corners that are<br />

inscribed by a 10 pixel circle, you would use this XAML:<br />

<br />

The Line<br />

Lines are drawn in XAML using the Line object. You specify the starting point of the line<br />

using its X1 <strong>and</strong> Y1 properties, <strong>and</strong> its endpoint using its X2 <strong>and</strong> Y2 properties. Note that<br />

these are not absolute coordinates, but relative to the container of the line. For example,<br />

if you have the line within a Canvas that has a top of 50 <strong>and</strong> a left of 50, <strong>and</strong> X1 <strong>and</strong> Y1 are<br />

both set to 50, then the line will start drawing from (100,100).<br />

The line itself can also have its Canvas.Top <strong>and</strong> Canvas.Left properties set to change<br />

its overall drawing position. Here’s an example:<br />

<br />

The Path<br />

The Path draws a series of connected lines <strong>and</strong> curves that are defined using a geometry.<br />

<strong>Silverlight</strong> uses the following geometries:<br />

EllipseGeometry: Defines the path element as a simple ellipse.<br />

LineGeometry: Defines the path element as a line.<br />

RectangleGeometry: Defines the path element as a rectangle.<br />

PathGeometry: Defines the path element using a complex set of different shapes,<br />

including arcs, Bézier curves, lines, poly Bézier curves, polyquadratic Bézier curves,<br />

<strong>and</strong> quadratic Bézier curves. When using a PathGeometry, you collect segments into a<br />

PathFigure, <strong>and</strong> one or more of these make up the PathGeometry. This goes beyond the<br />

scope of this book, but check out the MSDN documentation for more details.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!