Logo
HOW TO
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
 
 
Windows Phone

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

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
 
 
REVIEW
- First look: Apple Watch

- 10 Amazing Tools You Should Be Using with Dropbox
 
VIDEO TUTORIAL
- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
 
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
Popular keywords
HOW TO Swimlane in Visio Visio sort key Pen and Touch Creating groups in Windows Server Raid in Windows Server Exchange 2010 maintenance Exchange server mail enabled groups Debugging Tools Collaborating
Top 10
- Microsoft Excel : How to Use the VLookUp Function
- Fix and Tweak Graphics and Video (part 3) : How to Fix : My Screen Is Sluggish - Adjust Hardware Acceleration
- Fix and Tweak Graphics and Video (part 2) : How to Fix : Text on My Screen Is Too Small
- Fix and Tweak Graphics and Video (part 1) : How to Fix : Adjust the Resolution
- Windows Phone 8 Apps : Camera (part 4) - Adjusting Video Settings, Using the Video Light
- Windows Phone 8 Apps : Camera (part 3) - Using the Front Camera, Activating Video Mode
- Windows Phone 8 Apps : Camera (part 2) - Controlling the Camera’s Flash, Changing the Camera’s Behavior with Lenses
- Windows Phone 8 Apps : Camera (part 1) - Adjusting Photo Settings
- MDT's Client Wizard : Package Properties
- MDT's Client Wizard : Driver Properties
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro