Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Phone

Windows Phone 7 : The Silverlight Controls (part 3) - Line, Polyline, and Polygon Controls

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
1/20/2014 1:54:27 AM
1.5. Line, Polyline, and Polygon Controls

While we are discussing the Ellipse and Rectangle shape controls, it seems an appropriate time to also look at three additional shape-based controls. The Line control allows a simple straight line to be drawn within a page. Polyline controls allow a series of lines to be joined together. Finally, Polygon extends this further to create a solid shape from a number of lines and optionally fill its interior.

None of these controls is available from the Toolbox; instead, they must be manually created within the XAML editor. Once the control has been declared, all its properties can be viewed and modified in the Properties window as usual.

The Line requires two coordinates to be specified, for the start and end of the line. They are specified in pixels, relative to the top-left corner of their container. They also provide all the Stroke properties that we looked at for the Ellipse and Rectangle controls, allowing the line color, thickness, dashes, and so on to be configured.

Listing 3 shows the XAML required to create a line from coordinate (50, 50) to (200, 200).

Example 3. Creating a Line
<Line Stroke="SkyBlue" StrokeThickness="15" X1="50" Y1="50" X2="200" Y2="200" />


Lines that have sufficient thickness will by default appear with flat ends. They can be changed by capping the line ends so that they have a different shape. This is controlled by the StrokeStartLineCap and StrokeEndLineCap properties, each of which can be set to one of Flat (the default), Square, Round, or Triangle.

The next shape is the Polyline, which allows a series of coordinates to be provided and joined together using a series of lines. The coordinates this time are specified as X,Y pairs using the shape's Points property. Listing 4 shows a Polyline that creates a zig-zag shape within its container.

Example 4. Creating a Polyline
<Polyline Stroke="SkyBlue" StrokeThickness="15"
Points="100,50 200,100 100,150 200,200 100,250 " />


Besides simply joining between the points, the Polyline can provide additional flexibility around the corner points of the rendered lines. They are controlled using the StrokeLineJoin property, which can be set to one of Miter (the corners are extended into points), Bevel (the corners are flattened), or Round (the corners are rounded). Figure 6 shows the Polyline defined in Listing 4, but with each of the available StrokeLineJoin styles applied: Miter on the left, Bevel in the middle, and Round on the right.

Figure 6. Polylines using each of the available StrokeLineJoin properties

Just like Lines, PolyLines also allow their start and end to be capped if needed.

The final shape is the Polygon, which is configured in exactly the same way as the Polyline, but it creates an enclosed region (the end point is automatically joined back to the start point). It supports all the same features as the Polyline, except for the stroke start and end line caps because the Polygon doesn't have any start or end point.

What it provides instead is the ability to set its Fill property, resulting in a solid interior to the rendered shape. Any of the available brushes can be used for this purpose.

Listing 5 shows the XAML for a filled Polygon.

Example 5. Creating a Polygon
<Polygon Stroke="SkyBlue" StrokeThickness="15" Fill="Gold"
Points="100,50 200,100 150,150 200,200 100,250 " />


The resulting shape is shown in Figure 7.

Figure 7. The result of creating the filled Polygon
Other -----------------
- Windows Phone 7 : The Silverlight Controls (part 1) - Display Controls -TextBlock Controls, Image Controls, ProgressBar Controls
- Windows Phone 8 : Using Sound (part 2) - Recording Sounds
- Windows Phone 8 : Using Sound (part 1) - Playing Sounds with MediaElement, Using XNA Libraries, Playing Sounds with XNA, Adjusting Playback
- Windows Phone 8 : Localizing Your Phone Application
- Windows Phone 7 : Running Silverlight Projects in the Browser (part 2)
- Windows Phone 7 : Running Silverlight Projects in the Browser (part 1)
- Windows Phone 7 : Running XNA Projects in Windows (part 5)
- Windows Phone 7 : Running XNA Projects in Windows (part 4) - Converting the Game Framework to Run on Windows
- Windows Phone 7 : Running XNA Projects in Windows (part 3) - Input Differences, Isolated Storage, Application Life Cycle
- Windows Phone 7 : Running XNA Projects in Windows (part 2) - Display Differences
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server