Silverlight/XAML – Learning by Coding

[ sl2_xamlreader.xaml --> Grafik anzeigen ]

 1: <?xml version="1.0" encoding="UTF-8"?>
 2: <!-- coded by Thomas Meinike 10/08 -->
 3: <UserControl x:Class="sl2_xamlreader.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 Loaded="XAMLReader"/>
 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 XAMLReader(ByVal sender As System.Object_
21:                            ByVal e As System.Windows.RoutedEventArgs)
22: 
23:       'Rectangle- und textBlock-Elemente aus XAML-Strings erzeugen:
24:       Dim xaml_rect As String _
25:         "<Rectangle xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' " _
26:         "Canvas.Left='30' Canvas.Top='30' Width='200' Height='100' Fill='#6CF'/>"
27: 
28:       Dim xaml_text As String _
29:         "<TextBlock xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' " _
30:         "Canvas.Left='35' Canvas.Top='150' Foreground='#999' " _
31:         "FontFamily='Arial' FontSize='12' Text='Rechteck + Text dynamisch erzeugt'/>"
32: 
33:       Dim rectangle DirectCast(System.Windows.Markup.XamlReader.Load(xaml_rect), Rectangle)
34:       sender.Children.Add(rectangle)
35: 
36:       Dim textblock DirectCast(System.Windows.Markup.XamlReader.Load(xaml_text), TextBlock)
37:       sender.Children.Add(textblock)
38: 
39:       '==============================================================================================
40: 
41:       'Objekte aus XAML-Dokument objekte.xaml einlesen:
42:       Dim xaml_file As Uri = New Uri("objekte.xaml"UriKind.Relative)
43:       Dim xaml_stream As System.Windows.Resources.StreamResourceInfo _
44:         System.Windows.Application.GetResourceStream(xaml_file)
45: 
46:       Dim canvas As Canvas
47: 
48:       If Not xaml_stream Is Nothing Then
49:         Using xaml_reader As System.IO.StreamReader = New System.IO.StreamReader(xaml_stream.Stream)
50:           canvas DirectCast(System.Windows.Markup.XamlReader.Load(xaml_reader.ReadToEnd()), Canvas)
51:           sender.Children.Add(canvas)
52:         End Using
53:       End If
54: 
55:     End Sub
56: 
57:   End Class
58: 
59:   -->
60: 
61: 
62:   <!-- // zusätzlich verwendeter XAML-Code in objekte.xaml
63: 
64:   <?xml version="1.0" encoding="UTF-8"?>
65:   <Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
66:           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
67: 
68:     <Ellipse Canvas.Left="260" Canvas.Top="30" Width="150" Height="150" Fill="#C00"/>
69: 
70:     <Ellipse Canvas.Left="285" Canvas.Top="55" Width="100" Height="100" Fill="#0C0"/>
71: 
72:     <Ellipse Canvas.Left="310" Canvas.Top="80" Width="50" Height="50" Fill="#00C"/>
73: 
74:     <TextBlock Canvas.Left="275" Canvas.Top="200" Foreground="#999"
75:       FontFamily="Arial" FontSize="12" Text="Inhalt von objekte.xaml"/>
76: 
77:   </Canvas>
78: 
79:   -->
80: 
81: </UserControl>

[zum Anfang]