Silverlight/XAML – Learning by Coding
1: <?xml version="1.0" encoding="UTF-8"?>
2: <!-- coded by Thomas Meinike 05/08 -->
3: <Canvas xmlns="http://schemas.microsoft.com/client/2007"
4: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5: x:Name="container" Loaded="LoadXAML_2">
6:
7: <TextBlock Canvas.Left="30" Canvas.Top="15" Foreground="#999"
8: FontFamily="Lucida" FontSize="18" Text="XAML-Inhalte dynamisch aus externen Dateien laden"/>
9:
10: <TextBlock x:Name="fehler" Canvas.Left="30" Canvas.Top="50" FontFamily="Arial" FontSize="16"
11: Foreground="#F00" Text="Fehler bei der Datenabfrage!" Visibility="Collapsed"/>
12:
13:
14: <!-- // zusätzlich verwendeter JavaScript-Code:
15:
16: function LoadXAML_2(sender,eventArgs)
17: {
18: var sl_ctrl,cont_obj,xaml_obj,fehler_obj,dl;
19:
20: sl_ctrl=sender.getHost();
21: cont_obj=sender.findName("container");
22: fehler_obj=sender.findName("fehler");
23:
24: dl=sl_ctrl.createObject("downloader");
25:
26: dl.addEventListener("DownloadFailed",function(sender,eventArgs)
27: {
28: fehler_obj.visibility="Visible";
29: });
30:
31: dl.addEventListener("Completed",function(sender,eventArgs)
32: {
33: if(sender.status==200)
34: {
35: for(var i=1;i<=2;i++)
36: {
37: var xaml_obj=sl_ctrl.content.createFromXamlDownloader(sender,"objekt"+i+".xaml");
38: if(xaml_obj=="Canvas")cont_obj.children.add(xaml_obj); // oder cont_obj.children.insert(0,xaml_obj)
39: }
40: }
41: else fehler_obj.visibility="Visible";
42: });
43:
44: dl.open("GET","media/objekte.zip"); // enthält objekt1.xaml und objekt2.xaml
45: dl.send();
46: }
47:
48: -->
49:
50:
51: <!-- // zusätzlich verwendeter XAML-Code in objekt1.xaml:
52:
53: <?xml version="1.0" encoding="UTF-8"?>
54: <Canvas xmlns="http://schemas.microsoft.com/client/2007"
55: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
56:
57: <Rectangle Canvas.Left="30" Canvas.Top="70"
58: Width="200" Height="100" Fill="#6C9" Stroke="#CCC"/>
59:
60: <TextBlock Canvas.Left="30" Canvas.Top="200" Foreground="#999"
61: FontFamily="Arial" FontSize="12" Text="Inhalt von objekt1.xaml in objekte.zip"/>
62:
63: </Canvas>
64:
65: -->
66:
67:
68: <!-- // zusätzlich verwendeter XAML-Code in objekt2.xaml:
69:
70: <?xml version="1.0" encoding="UTF-8"?>
71: <Canvas xmlns="http://schemas.microsoft.com/client/2007"
72: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
73:
74: <Ellipse Canvas.Left="290" Canvas.Top="70"
75: Width="200" Height="100" Fill="#96C" Stroke="#CCC"/>
76:
77: <TextBlock Canvas.Left="295" Canvas.Top="200" Foreground="#999"
78: FontFamily="Arial" FontSize="12" Text="Inhalt von objekt2.xaml in objekte.zip"/>
79:
80: </Canvas>
81:
82: -->
83:
84: </Canvas>
[zum Anfang]