|
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
namespace Facebook.Windows
{
/// <summary>
/// Interaction logic for Facebook.Windows.WaitPage.xaml
/// </summary>
public partial class WaitPage : Page
{
public WaitPage()
{
InitializeComponent();
}
private void PageGrid_Loaded(object sender, RoutedEventArgs e)
{
PopulateuiEllipseClockFace(); // Kick off the population of the clock face
}
/// <summary>
/// Populate the face of the clock with tick marks for minutes.
/// Irrelavant, but got waylaid playing with WFP :)
/// </summary>
public void PopulateuiEllipseClockFace()
{
double radius = uiEllipseClockFace.Width / 2;
double circumference = Math.PI * Math.Pow(radius, 2);
// Ellipse (Clock) Center
Point clockCenter = new Point(
((uiEllipseClockFace.RenderedGeometry.Bounds.Left + uiEllipseClockFace.RenderedGeometry.Bounds.Right) / 2),
(uiEllipseClockFace.RenderedGeometry.Bounds.Top + uiEllipseClockFace.RenderedGeometry.Bounds.Bottom) / 2);
// Ellipse (Clock) LeftMost
Point clockLeftMost = new Point(uiEllipseClockFace.RenderedGeometry.Bounds.Left,
(uiEllipseClockFace.RenderedGeometry.Bounds.TopLeft.Y + uiEllipseClockFace.RenderedGeometry.Bounds.BottomLeft.Y) / 2);
const int NumberOfMarksOnuiEllipseClockFace = 60;
const int offset = 8; // When you fiddle the line lengths, this parameter becomes important to keep things square
// Layout the clock face
for (int i = 0; i <= NumberOfMarksOnuiEllipseClockFace; i++)
{
var clockMarkerLine = new Line();
// Set out the co-ordinates to draw a line from ellipse center (uiEllipseClockFace) to the ellipse bpundary.
clockMarkerLine.X1 = (uiEllipseClockFace.RenderedGeometry.Bounds.TopLeft.X - uiEllipseClockFace.StrokeThickness / 2);
clockMarkerLine.Y1 = (uiEllipseClockFace.RenderedGeometry.Bounds.TopLeft.Y + radius - uiEllipseClockFace.StrokeThickness / 2) - offset;
clockMarkerLine.X2 = clockMarkerLine.X1;
clockMarkerLine.Y2 = clockMarkerLine.Y1 + radius;
// Need to persist the original center (to rotate around) before playing with the lines
double xCenter = clockMarkerLine.X1;
double yCenter = clockMarkerLine.Y1;
// Fiddle the center to circle line lengths to make small marks instead of full lines. Comment out the 2 lines below to see how it works)
clockMarkerLine.Y1 = clockMarkerLine.Y1 + radius - 10; // change start of line
clockMarkerLine.Y2 = clockMarkerLine.Y2 - offset; // Change end of line
clockMarkerLine.Stroke = System.Windows.Media.Brushes.BurlyWood; // Pick a color
clockMarkerLine.HorizontalAlignment = uiEllipseClockFace.HorizontalAlignment; // Ensure same alignement
clockMarkerLine.VerticalAlignment = uiEllipseClockFace.VerticalAlignment; // Ensure same alignement
clockMarkerLine.StrokeThickness = 3; // How thick should the line be
clockMarkerLine.RenderTransform = new RotateTransform((360 / NumberOfMarksOnuiEllipseClockFace) * i, xCenter, yCenter); // Plot each line at an increasing angle.
PageGrid.Children.Add(clockMarkerLine); // Add the line
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.