Silverlight/XAML – Learning by Coding

[ sl2_dynamic_objects.xaml --> Grafik anzeigen ]

 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 ObjectByVal e As RoutedEventArgs)
21:       Dim rect As New Rectangle
22:       With rect
23:         .Width 200
24:         .Height 100
25:         .SetValue(Canvas.LeftProperty30.0)
26:         .SetValue(Canvas.TopProperty30.0)
27:         .Fill = New SolidColorBrush(Color.FromArgb(2552552550)) 'Gelb
28:         .Stroke = New SolidColorBrush(Color.FromArgb(25525500)) 'Rot
29:         .StrokeThickness 2
30:       End With
31: 
32:       Dim text As New TextBlock
33:       With text
34:         .SetValue(Canvas.LeftProperty30.0)
35:         .SetValue(Canvas.TopProperty150.0)
36:         .Foreground = New SolidColorBrush(Color.FromArgb(25500255)) '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]