De XAML:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Grid Width="300" Height="300">
<Ellipse Width="300" Height="300" Fill="Blue"></Ellipse>
<Rectangle Margin="150,0,149,150" Name="rectangleSecond"
Stroke="White" Height="120" VerticalAlignment="Bottom">
<Rectangle.RenderTransform>
<RotateTransform x:Name="secondHand" CenterX="0"
CenterY="120" Angle="0" />
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle Margin="150,49,149,151" Name="rectangleMinute"
Stroke="LightGreen">
<Rectangle.RenderTransform>
<RotateTransform x:Name="minuteHand" CenterX="0"
CenterY="100" Angle="0" />
</Rectangle.RenderTransform>
<RotateTransform x:Name="minuteHand" CenterX="0"
__tag_end" style="color:maroon;font-weight:bold;"></Rectangle>
<Rectangle Margin="150,80,149,150" Name="rectangleHour"
Stroke="LightYellow">
<Rectangle.RenderTransform>
<RotateTransform x:Name="hourHand" CenterX="0"
CenterY="70" Angle="0" />
</Rectangle.RenderTransform>
</Rectangle>
</Grid>
</Grid>
De C# code:
DispatcherTimer timer = new DispatcherTimer();
public MainPage()
{
this.InitializeComponent();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += timer_Tick;
timer.Start();
}
void timer_Tick(object sender, object e)
{
secondHand.Angle = DateTime.Now.Second * 6;
minuteHand.Angle = DateTime.Now.Minute * 6;
hourHand.Angle = (DateTime.Now.Hour * 30) + (DateTime.Now.Minute * 0.5);
}
Andere talen
Dit artikel is ook verkrijgbaar in de volgende talen: