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_dynamic_objects.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 x:Name="dyncanvas" Loaded="GenerateXAML"/>
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 GenerateXAML(ByVal sender As Object, ByVal e As RoutedEventArgs)
21: Dim rect As New Rectangle
22: With rect
23: .Width = 200
24: .Height = 100
25: .SetValue(Canvas.LeftProperty, 30.0)
26: .SetValue(Canvas.TopProperty, 30.0)
27: .Fill = New SolidColorBrush(Color.FromArgb(255, 255, 255, 0)) 'Gelb
28: .Stroke = New SolidColorBrush(Color.FromArgb(255, 255, 0, 0)) 'Rot
29: .StrokeThickness = 2
30: End With
31:
32: Dim text As New TextBlock
33: With text
34: .SetValue(Canvas.LeftProperty, 30.0)
35: .SetValue(Canvas.TopProperty, 150.0)
36: .Foreground = New SolidColorBrush(Color.FromArgb(255, 0, 0, 255)) 'Blau
37: .FontFamily = New FontFamily("Arial")
38: .FontSize = 14
39: .Text = "Das Rechteck und dieser Text wurden dynamisch erzeugt."
40: End With
41:
42: dyncanvas.Children.Add(rect)
43: dyncanvas.Children.Add(text)
44: End Sub
45:
46: End Class
47:
48: -->
49:
50: </UserControl>
[zum Anfang]