Silverlight/XAML – Learning by Coding
1: <?xml version="1.0" encoding="UTF-8"?>
2: <!-- coded by Thomas Meinike 10/08 -->
3: <UserControl x:Class="sl2_random_circles.Page"
4: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6: Width="800" Height="600">
7:
8: <Canvas Background="#EEE" Loaded="RandomCircles"/>
9:
10:
11: <!-- // zusätzlich verwendeter VB.NET-Code in Page.xaml.vb:
12:
13: Partial Public Class Page
14: Inherits UserControl
15:
16: Public Sub New()
17: InitializeComponent()
18: End Sub
19:
20: Private Sub RandomCircles(ByVal sender As System.Object, _
21: ByVal e As System.Windows.RoutedEventArgs)
22: Dim i As Short, wh As Double
23:
24: 'Kreise mit Zufallsfarben und -positionen erzeugen
25: For i = 1 To 1000
26: Dim circle As New Ellipse
27: With circle
28: Randomize()
29:
30: 'Kreisdurchmesser und -position
31: wh = Math.Ceiling(100 * Rnd())
32: .Width = wh
33: .Height = wh
34: .SetValue(Canvas.LeftProperty, (800 - wh) * Rnd())
35: .SetValue(Canvas.TopProperty, (600 - wh) * Rnd())
36:
37: 'Tooltip i=... : d=...
38: .SetValue(ToolTipService.ToolTipProperty, _
39: "i=" + i.ToString + " : d=" + wh.ToString)
40:
41: 'ARGB-Zufallsfarben
42: .Fill = New SolidColorBrush(Color.FromArgb( _
43: Math.Floor(256 * Rnd()), _
44: Math.Floor(256 * Rnd()), _
45: Math.Floor(256 * Rnd()), _
46: Math.Floor(256 * Rnd())))
47: End With
48: sender.Children.Add(circle)
49: Next
50: End Sub
51:
52: End Class
53:
54: -->
55:
56: </UserControl>
[zum Anfang]