<UserControl x:Class="ListBoxSnippets.Page"
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="370">
<StackPanel x:Name="LayoutRoot" Background="White" Margin="10,10,10,10">
<TextBlock Text="ListBox Demonstration" Margin="0,20,10,20"
FontFamily="Verdana" FontSize="18" FontWeight="Bold"
Foreground="#FF5C9AC9" />
<TextBlock Text="ListBox with unbound data:" />
<ListBox Width="350" Margin="0,5,0,10">
<TextBlock Text="TextBlock" />
<TextBox Text="TextBox" />
<Button Content="Button" />
<Rectangle Fill="LightBlue" Height="20" Width="150" Margin="2,2,2,2"/>
<Ellipse Fill="Coral" Height="20" Width="150" Margin="2,2,2,2"/>
</ListBox>
<TextBlock Text="ListBox with bound data:" />
<ListBox x:Name="listBox1" Width="350" Margin="0,5,0,10"
DisplayMemberPath="LastName"/>
<TextBlock Text="ListBox with ItemTemplate:" />
<ListBox x:Name="listBox2" Width="350" Margin="0,5,0,10">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Padding="5,0,5,0"
Text="{Binding FirstName}" />
<TextBlock Text="{Binding LastName}" />
<TextBlock Text=", " />
<TextBlock Text="{Binding Address}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock Text="ListBox with SelectionChanged event handler:" />
<ListBox Width="350" Margin="0,5,0,5" SelectionChanged="PrintText" >
<ListBoxItem Content="Item 1" />
<ListBoxItem Content="Item 2" />
<ListBoxItem Content="Item 3" />
<ListBoxItem Content="Item 4" />
<ListBoxItem Content="Item 5" />
</ListBox>
<TextBlock Name="textBlock1" />
</StackPanel>
</UserControl>
|