Silverlight/XAML – Learning by Coding
1: <?xml version="1.0" encoding="UTF-8"?>
2: <!-- coded by Thomas Meinike 09/08 -->
3: <UserControl x:Class="sl2_custom_control.Page"
4: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6: xmlns:cc="clr-namespace:sl2_custom_control"
7: Width="800" Height="600">
8:
9: <Canvas>
10: <TextBlock Canvas.Left="30" Canvas.Top="30" FontFamily="Arial" FontSize="24"
11: Foreground="#00C" Text="Eingabefeld als Custom Control (3x referenziert)"/>
12:
13: <cc:TEingabefeld x:Name="feld1" Margin="30,70,0,10" VerticalAlignment="Top"
14: TBoxWidth="300" TBoxName="Feldname 1" TBoxText=""/><!-- Standardhintergrund #FFF -->
15:
16: <cc:TEingabefeld x:Name="feld2" Margin="30,150,0,10" VerticalAlignment="Top"
17: TBoxWidth="400" TBoxName="Feldname 2" TBoxText="" TBoxBackground="#FFC"/>
18:
19: <cc:TEingabefeld x:Name="feld3" Margin="30,230,0,10" VerticalAlignment="Top"
20: TBoxName="Feldname 3" TBoxText="" TBoxBackground="#9C6"/><!-- Standardbreite 500 -->
21: </Canvas>
22:
23:
24: <!-- // zusätzlich verwendeter VB.NET-Code in Page.xaml.vb:
25:
26: Partial Public Class Page
27: Inherits UserControl
28:
29: Public Sub New()
30: InitializeComponent()
31: End Sub
32:
33: Private Sub Page_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
34: feld1.Focus() 'Fokus setzen funktioniert offenbar nicht?
35: End Sub
36:
37: End Class
38:
39: -->
40:
41:
42: <!-- // zusätzlich verwendeter VB.NET-Code in cc_eingabefeld.xaml:
43:
44: <UserControl
45: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
46: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
47: x:Class="sl2_custom_control.TEingabefeld">
48:
49: <Canvas>
50: <Border x:Name="cc_TBox_Border" Height="65" Margin="0,0,0,0" VerticalAlignment="Top" BorderThickness="1,1,1,1"
51: CornerRadius="10,10,10,10" BorderBrush="#CCC" Padding="10,10,10,10" Width="500" HorizontalAlignment="Left"
52: Background="#FFF"/>
53:
54: <TextBlock x:Name="cc_TBox_Name" Height="20" HorizontalAlignment="Left" Margin="10,10,10,10"
55: VerticalAlignment="Top" Width="480" Text="TextBlock" TextWrapping="Wrap" FontSize="12"/>
56:
57: <TextBox x:Name="cc_TBox_Text" Height="Auto" HorizontalAlignment="Left" Margin="10,30,0,0"
58: VerticalAlignment="Top" Width="480" Text="TextBox" TextWrapping="Wrap" FontFamily="Arial" FontSize="16"/>
59: </Canvas>
60:
61: </UserControl>
62:
63: -->
64:
65:
66: <!-- // zusätzlich verwendeter VB.NET-Code in cc_eingabefeld.xaml.vb:
67:
68: Imports System
69: Imports System.Windows
70: Imports System.Windows.Controls
71: Imports System.Windows.Media
72: Imports System.Windows.Media.Animation
73: Imports System.Windows.Shapes
74:
75: Partial Public Class TEingabefeld
76: Inherits UserControl
77:
78: Public Sub New()
79: InitializeComponent()
80: End Sub
81:
82: Property TBoxText() As String
83: Get
84: Return cc_TBox_Text.Text
85: End Get
86: Set(ByVal value As String)
87: cc_TBox_Text.Text = value
88: End Set
89: End Property
90:
91: Property TBoxName() As String
92: Get
93: Return cc_TBox_Name.Text
94: End Get
95: Set(ByVal value As String)
96: cc_TBox_Name.Text = value
97: End Set
98: End Property
99:
100: Property TBoxWidth() As Double
101: Get
102: Return cc_TBox_Border.Width
103: End Get
104: Set(ByVal value As Double)
105: cc_TBox_Border.Width = value
106: cc_TBox_Name.Width = value - 20
107: cc_TBox_Text.Width = value - 20
108: End Set
109: End Property
110:
111: Property TBoxBackground() As SolidColorBrush
112: Get
113: Return cc_TBox_Border.Background
114: End Get
115: Set(ByVal value As SolidColorBrush)
116: cc_TBox_Border.Background = value
117: End Set
118: End Property
119:
120: End Class
121:
122: -->
123:
124: </UserControl>
[zum Anfang]