Silverlight/XAML – Learning by Coding

[ sl2_dlr_jscript.xaml --> Grafik anzeigen ]

 1: <?xml version="1.0" encoding="UTF-8"?>
 2: <!-- coded by Thomas Meinike 08/08 -->
 3: <UserControl x:Class="System.Windows.Controls.UserControl"
 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="flaeche">
 9:     <TextBlock x:Name="ausgabe"/>
10:   </Canvas>
11: 
12: 
13:   <!-- // zusätzlich verwendeter JScript-Code in app.jsx (XAP-Datei mit Chiron.exe erstellt):
14: 
15:   Import("System.Windows.Application");
16:   Import("System.Windows.Controls.*");
17:   Import("System.Windows.Shapes.*");
18:   Import("System.Windows.Media.*");
19: 
20: 
21:   var xamlroot=Application.Current.LoadRootVisual(new UserControl(),"app.xaml");
22:   xamlroot.Loaded += DLR_Test;
23: 
24: 
25:   function DLR_Test(sender,eventArgs)
26:   {
27:     // Text ausgeben
28:     var ausgabe=sender.findName("ausgabe");
29:     ausgabe.SetValue(Canvas.LeftProperty,30);
30:     ausgabe.SetValue(Canvas.TopProperty,30);
31:     ausgabe.Foreground=new SolidColorBrush(Colors.Red);
32:     ausgabe.FontSize=24;
33:     ausgabe.Text="Dynamic Language Runtime (DLR) mit JScript in Aktion";
34: 
35: 
36:     // Rechtecke ausgeben
37:     var farben=["#FFFF66","#FFCC33","#FF99FF","#00FF66","#00CCFF"];
38:     for(var i=0;i<5;i++)
39:     {   
40:       var rect=new Rectangle();
41:       rect.Width=50*(i+1);
42:       rect.Height=25*(i+1);
43:       rect.SetValue(Canvas.LeftProperty,30+i/2*(rect.Width));
44:       rect.SetValue(Canvas.TopProperty,80+i/2*(rect.Height));
45:       rect.Fill=new SolidColorBrush(getArgbColor(farben[i]));
46:   
47:       sender.findName("flaeche").children.add(rect);
48:     }
49:   }
50: 
51: 
52:   function getArgbColor(hexcolor)
53:   {
54:     var r=parseInt(hexcolor.substr(1,2),16);
55:     var g=parseInt(hexcolor.substr(3,2),16);
56:     var b=parseInt(hexcolor.substr(5,2),16);
57: 
58:     return Color.FromArgb(255,r,g,b);
59:   }
60: 
61:   -->
62: 
63: </UserControl>

[zum Anfang]