Silverlight/XAML – Learning by Coding
1: <?xml version="1.0" encoding="UTF-8"?>
2: <!-- coded by Thomas Meinike 01/09 -->
3: <UserControl x:Class="sl2_initparams.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="GetParams">
9: <TextBlock Canvas.Left="30" Canvas.Top="20" Foreground="#00F"
10: FontSize="24" Text="initParams aus object auswerten (text/size)"/>
11: <TextBlock x:Name="tblock" Canvas.Left="30" Canvas.Top="50" Foreground="#F00"/>
12: </Canvas>
13:
14:
15: <!-- // zusätzlich verwendeter VB.NET-Code in Page.xaml.vb:
16:
17: Partial Public Class Page
18: Inherits UserControl
19:
20: Public Sub New()
21: InitializeComponent()
22: End Sub
23:
24: Private Sub GetParams(ByVal sender As System.Object, _
25: ByVal e As System.Windows.RoutedEventArgs)
26: tblock.Text = App.Current.Resources("text").ToString
27: tblock.FontSize = App.Current.Resources("size").ToString
28: End Sub
29:
30: End Class
31:
32: -->
33:
34:
35: <!-- // zusätzlich verwendeter VB.NET-Code in App.xaml.vb:
36:
37: Private Sub Application_Startup(ByVal o As Object, _
38: ByVal e As StartupEventArgs) Handles Me.Startup
39: Me.RootVisual = New Page()
40:
41: If e.InitParams.ContainsKey("text") Then
42: Me.Resources.Add("text", e.InitParams("text"))
43: Else
44: Me.Resources.Add("text", "text-Parameter nicht vorhanden!")
45: End If
46:
47: If e.InitParams.ContainsKey("size") Then
48: Me.Resources.Add("size", e.InitParams("size"))
49: Else
50: Me.Resources.Add("size", "28")
51: End If
52: End Sub
53:
54: -->
55:
56:
57: <!-- // zusätzlich verwendeter HTML-Code zur Silverlight-Einbindung:
58:
59: <param name="initParams" value="text=Hallo Silverlight!,size=28" />
60:
61: -->
62:
63: </UserControl>
[zum Anfang]