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 2) - Display Controls - Ellipse and Rectangle 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:53:12 AM
1.4. Ellipse and Rectangle Controls

As you might expect, these controls allow ellipses, circles, rectangles, and squares to be placed inside your page. They can be filled (using all the available brushes) or transparent, and can have a border around them.

To create a circle or square, simply ensure that the ellipse or rectangle's Width and Height are set to the same value.

The interior of the shapes are filled using their Fill property, whereas their border is controlled using a series of properties whose names all begin with Stroke. The Stroke property itself sets the color, whereas the StrokeThickness sets the border width (though be aware that it starts at 0, making the border initially invisible).

The border offers up an extra feature that might be useful, however: it doesn't need to be a continuous line. One of the properties, StrokeDashArray, allows a dashed pattern to be configured for the border. This property cannot be edited via the Properties window, but can be directly entered into the XAML. Its value should be a list of numbers (separated by spaces) that define alternating length of filled and empty areas of the border.

For example, if this were set to a value of "1 1", the border would display dashes that were 1 unit long, followed by a gap that was also 1 unit long. Setting it to "3 1" would result in dashes 3 units long and gaps 1 unit long. More complex patterns can be formed by providing a larger pattern; "1 1 3 5" would result in a 1-unit dash, a 1-unit space, a 3-unit dash, and then a 5-unit space. Fractional numbers can be provided for any of these array elements, too.

The measurement unit that the border is using is the StrokeThickness. As this increases or decreases, so too do the lengths of the dashes.

Listing 2 shows how these properties can be used to create a filled ellipse with a dashed border.

Example 2. Creating a filled ellipse with a dashed border
<Ellipse Height="250" Width="250" Stroke="SkyBlue" StrokeThickness="15"
StrokeDashArray="3 3" Fill="Gray" />


The resulting ellipse is shown in Figure 3.

Figure 3. The resulting ellipse

Some additional options are available for the dashed border, too. The StrokeDashCap can be used to control the transition between the dashes and the empty space between. The default value for this property is Flat, but it can also be set to one of Square, Round, or Triangle. This difference can be seen in Figure 4, which uses the same ellipse as in Figure 3, but with each of the new dash cap values. Note that all these except for Flat will eat into the space allocated for the gaps, so if you want to use a dash cap while also retaining equal sizes of the dashes and gaps, you will need to manipulate the StrokeDashArray to accommodate the dash caps.

Figure 12.4. Dashed ellipses with Square, Round, and Triangle stroke dash caps

It is also possible to rotate the dashes around the ellipse by applying a StrokeDashOffset. This is measured in the same units as the StrokeDashArray is measured in, so if the total length of the stroke dashes is 6 units, the offset will produce identical results with a value of 0 or 6, but other values in between will change the positioning of the dashes. The StrokeDashOffset could be animated within a game to provide a simple implementation of a spinning outline box or disc—useful for highlighting selected game objects, for example.

The Rectangle offers a final pair of properties that might come in very handy: RadiusX and RadiusY. They allow rounded corners to be applied to the rectangle, and the elliptical rounding area will have its width and height defined by these two properties. Figure 5 shows a rectangle using a value of 15 for both of the corner radius properties.

Figure 5. A rectangle with rounded corners

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