Click here to Skip to main content
15,886,199 members
Articles / Desktop Programming / WPF

Immerse Yourself in WPF: A "World Clocks" Application as Literate Code

Rate me:
Please Sign up or sign in to vote.
4.88/5 (39 votes)
16 Aug 200713 min read 114.9K   5K   111  
Literate code describing how to build a simple "world clocks" application in WPF
<UserControl x:Class="BinaryComponents.WorldClocks.Controls.Clock"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    
    <Viewbox>
		<Canvas Width="100" Height="100" x:Name="_canvas">

			<Ellipse Canvas.Left="0" Canvas.Top="0" Width="100" Height="100">
				<Ellipse.Fill>
					<RadialGradientBrush>
						<GradientStop Offset="0.0" Color="White" />
						<GradientStop Offset="0.95" Color="White" />
						<GradientStop Offset="1.0" Color="Transparent" />
					</RadialGradientBrush>
				</Ellipse.Fill>
			</Ellipse>
			<Ellipse Canvas.Left="3" Canvas.Top="3" Width="94" Height="94">
				<Ellipse.Fill>
					<LinearGradientBrush StartPoint="0.4,0.1" EndPoint="0.6,0.9">
						<LinearGradientBrush.GradientStops>
							<GradientStop Offset="0.0" Color="#888888" />
							<GradientStop Offset="1.0" Color="#111111" />
						</LinearGradientBrush.GradientStops>
					</LinearGradientBrush>
				</Ellipse.Fill>
			</Ellipse>
			
			<Canvas x:Name="_markersCanvas" />
			
			<Canvas>
				<Canvas.BitmapEffect>
					<DropShadowBitmapEffect ShadowDepth="1" Softness="0.1" Opacity="0.5" />
				</Canvas.BitmapEffect>
				<Rectangle Width="8" Height="36" Fill="White" Stroke="#333333" StrokeThickness="0.6" RadiusX="2" RadiusY="2">
					<Rectangle.RenderTransform>
						<TransformGroup>
							<TranslateTransform X="-4" Y="-32" />
							<RotateTransform Angle="{Binding HourAngle}" />
							<TranslateTransform X="50" Y="50" />
						</TransformGroup>
					</Rectangle.RenderTransform>
				</Rectangle>
				
				<Rectangle Width="5" Height="44" Fill="White" Stroke="#333333" StrokeThickness="0.6" RadiusX="1" RadiusY="1">
					<Rectangle.RenderTransform>
						<TransformGroup>
							<TranslateTransform X="-2.5" Y="-41.5" />
							<RotateTransform Angle="{Binding MinuteAngle}" />
							<TranslateTransform X="50" Y="50" />
						</TransformGroup>
					</Rectangle.RenderTransform>
				</Rectangle>
			</Canvas>
			
			<Canvas>
				<Canvas.BitmapEffect>
					<DropShadowBitmapEffect ShadowDepth="1" Softness="0.05" Opacity="1.0" />
				</Canvas.BitmapEffect>
				<Rectangle Width="0.5" Height="46" Fill="White">
					<Rectangle.RenderTransform>
						<TransformGroup>
							<TranslateTransform X="-0.25" Y="-45.75" />
							<RotateTransform Angle="{Binding SecondAngle}" />
							<TranslateTransform X="50" Y="50" />
						</TransformGroup>
					</Rectangle.RenderTransform>
				</Rectangle>
			</Canvas>

			<Ellipse Canvas.Left="3" Canvas.Top="3" Width="94" Height="94">
				<Ellipse.Fill>
					<RadialGradientBrush Center="0.51,0.52" SpreadMethod="Pad">
						<GradientStop Offset="0.0" Color="Transparent" />
						<GradientStop Offset="0.9" Color="Transparent" />
						<GradientStop Offset="1.0" Color="#a0000000" />
					</RadialGradientBrush>
				</Ellipse.Fill>
			</Ellipse>
			<Ellipse Canvas.Left="3" Canvas.Top="3" Width="94" Height="94">
				<Ellipse.Fill>
					<RadialGradientBrush Center="0.7,0.8" SpreadMethod="Pad" RadiusX="1.3" RadiusY="1.2">
						<GradientStop Offset="0.0" Color="Transparent" />
						<GradientStop Offset="0.4" Color="#30ffffff" />
						<GradientStop Offset="0.5" Color="#60ffffff" />
						<GradientStop Offset="0.6" Color="#3fffffff" />
						<GradientStop Offset="1.0" Color="Transparent" />
					</RadialGradientBrush>
				</Ellipse.Fill>
			</Ellipse>
		</Canvas>
    </Viewbox>
</UserControl>

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United Kingdom United Kingdom
I'm currently working for a small start-up company, BinaryComponents Ltd, producing the FeedGhost RSS reader.

FeedGhost RSS Reader:
http://www.feedghost.com

Bespoke Software Development
http://www.binarycomponents.com

Comments and Discussions