Silverlight/XAML – Learning by Coding
1: <?xml version="1.0" encoding="UTF-8"?>
2: <!-- coded by Thomas Meinike 08/08 -->
3: <UserControl x:Class="sl2_databinding.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="DataBinding" x:Name="dyntext">
9:
10: <TextBlock Canvas.Left="30" Canvas.Top="30" Foreground="#00C" FontSize="18"
11: Text="DataBinding mit Textblöcken"/>
12: <TextBlock Canvas.Left="30" Canvas.Top="60" Foreground="#C00" FontSize="14"
13: Text="{Binding t1,Mode=OneWay}"/>
14: <TextBlock Canvas.Left="30" Canvas.Top="80" Foreground="#090" FontSize="14"
15: Text="{Binding t2,Mode=OneWay}"/>
16:
17: </Canvas>
18:
19:
20: <!-- // zusätzlich verwendeter VB.NET-Code in Page.xaml.vb:
21:
22: Partial Public Class Page
23: Inherits UserControl
24:
25: Public Class Data
26: Private _t1 As String
27: Private _t2 As String
28:
29: Property t1() As String
30: Get
31: Return _t1
32: End Get
33: Set(ByVal value As String)
34: _t1 = value
35: End Set
36: End Property
37:
38: Property t2() As String
39: Get
40: Return _t2
41: End Get
42: Set(ByVal value As String)
43: _t2 = value
44: End Set
45: End Property
46:
47: End Class
48:
49: Public Sub New()
50: InitializeComponent()
51: End Sub
52:
53: Private Sub DataBinding(ByVal sender As Object, ByVal e As RoutedEventArgs)
54: dyntext.DataContext = New Data With _
55: {.t1 = "erster dynamisch gebundener Text", _
56: .t2 = "zweiter dynamisch gebundener Text"}
57: End Sub
58:
59: End Class
60:
61: -->
62:
63: </UserControl>
[zum Anfang]