Silverlight/XAML – Learning by Coding
1: <?xml version="1.0" encoding="UTF-8"?>
2: <!-- coded by Thomas Meinike 10/08 -->
3: <UserControl x:Class="sl2_combobox.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>
9:
10: <ComboBox Width="250" Canvas.Left="30" Canvas.Top="30"
11: SelectionChanged="Auswahl" Padding="5" x:Name="combo">
12: <ComboBox.Items>
13: <ComboBoxItem Content="=== Auswahl ==="/>
14: <ComboBoxItem Content="Erster Eintrag"/>
15: <ComboBoxItem Content="Zweiter Eintrag"/>
16: <ComboBoxItem Content="Dritter Eintrag"/>
17: <ComboBoxItem Content="Vierter Eintrag"/>
18: <ComboBoxItem Content="Fünfter Eintrag"/>
19: </ComboBox.Items>
20: </ComboBox>
21:
22: <TextBlock Canvas.Left="290" Canvas.Top="35"
23: Foreground="#F00" Text="..." x:Name="ausgabe"/>
24:
25: </Canvas>
26:
27:
28: <!-- // zusätzlich verwendeter VB.NET-Code in Page.xaml.vb:
29:
30: Partial Public Class Page
31: Inherits UserControl
32:
33: Public Sub New()
34: InitializeComponent()
35: combo.SelectedIndex = 0
36: End Sub
37:
38: Private Sub Auswahl(ByVal sender As Object, _
39: ByVal e As System.Windows.Controls.SelectionChangedEventArgs)
40: If combo.SelectedIndex > 0 Then
41: ausgabe.Text = "Eintrag " + (combo.SelectedIndex).ToString + " wurde ausgewählt."
42: Else
43: ausgabe.Text = "..."
44: End If
45: End Sub
46:
47: End Class
48:
49: -->
50:
51: </UserControl>
[zum Anfang]