首页 / 软件开发 / Silverlight / 稳扎稳打Silverlight(5) - 2.0控件之ListBox,MediaElement,MultiScaleImage…
稳扎稳打Silverlight(5) - 2.0控件之ListBox,MediaElement,MultiScaleImage…2010-04-26 cnblogs webabcd稳扎稳打Silverlight(5) - 2.0控件之ListBox,MediaElement,MultiScaleImage,PasswordBox,ProgressBar,RadioButton在线DEMOhttp://www.cnblogs.com/webabcd/archive/2008/10/09/1307486.html示例1、ListBox.xaml<UserControl x:Class="Silverlight20.Control.ListBox" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <StackPanel HorizontalAlignment="Left"> <!-- SelectionChanged - ListBox中某个对象被选中后所触发的事件 --> <ListBox Margin="5" Width="200" Height="100" SelectionChanged="ListBox_SelectionChanged"> <ListBoxItem Content="ListBoxItem01" /> <ListBoxItem Content="ListBoxItem02" /> <ListBoxItem Content="ListBoxItem03" /> <ListBoxItem Content="ListBoxItem04" /> <ListBoxItem Content="ListBoxItem05" /> <ListBoxItem Content="ListBoxItem06" /> <ListBoxItem Content="ListBoxItem07" /> <ListBoxItem Content="ListBoxItem08" /> <ListBoxItem Content="ListBoxItem09" /> <ListBoxItem Content="ListBoxItem10" /> </ListBox> <!-- ListBox中可以包含任何对象 --> <ListBox Margin="5" Width="200"> <TextBlock Text="TextBlock" /> <TextBox Text="TextBox" /> <Button Content="Button" /> </ListBox> </StackPanel> </UserControl>ListBox.xaml.csusing System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.Windows.Browser; namespace Silverlight20.Control { public partial class ListBox : UserControl { public ListBox() { InitializeComponent(); } private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { // ListBox.SelectedItem - ListBox中被选中的对象 var lst = sender as System.Windows.Controls.ListBox; MessageBox.Show( ((System.Windows.Controls.ListBoxItem)lst.SelectedItem).Content + " 被单击了", "提示", MessageBoxButton.OK); } } }
收藏该网址