Silverlight/XAML – Learning by Coding
1: <?xml version="1.0" encoding="UTF-8"?>
2: <!-- coded by Thomas Meinike 08/08 -->
3: <UserControl x:Class="sl2_random_colors.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>
9:
10: <Ellipse Canvas.Left="30" Canvas.Top="30" Width="150" Height="150" Fill="#FFF" Stroke="#CCC"
11: StrokeThickness="1" x:Name="circle" MouseLeftButtonDown="RandomColor"/>
12:
13: <TextBlock Canvas.Left="200" Canvas.Top="95" Text="ARGB(255,255,255,255)" x:Name="argb"/>
14: <TextBlock Canvas.Left="60" Canvas.Top="200" Text="Kreis anklicken!"/>
15:
16: </Canvas>
17:
18:
19: <!-- // zusätzlich verwendeter VB.NET-Code in Page.xaml.vb:
20:
21: Partial Public Class Page
22: Inherits UserControl
23:
24: Public Sub New()
25: InitializeComponent()
26: End Sub
27:
28: Private Sub RandomColor(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)
29: Randomize()
30: Dim a = Math.Floor(256 * Rnd())
31: Dim r = Math.Floor(256 * Rnd())
32: Dim g = Math.Floor(256 * Rnd())
33: Dim b = Math.Floor(256 * Rnd())
34:
35: circle.Fill = New SolidColorBrush(Color.FromArgb(a, r, g, b))
36: argb.Text = "ARGB(" + a.ToString + "," + r.ToString + "," + g.ToString + "," + b.ToString + ")"
37: End Sub
38:
39: End Class
40:
41: -->
42:
43: </UserControl>
[zum Anfang]