Silverlight(17) - 2.0数据之详解DataGrid, 详解ListBox
2008-12-08 11:51:53 来源:WEB开发网3、ListBox.xaml
<UserControl x:Class="Silverlight20.Data.ListBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left">
<!--
ListBox.ItemTemplate - ListBox 的选项模板
DataTemplate - 手工定义 ListBox 的选项数据
-->
<ListBox x:Name="ListBox1" Margin="5" Width="200" Height="100">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" Margin="5" />
<TextBlock Text="{Binding Age}" Margin="5" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</UserControl>
ListBox.xaml.cs
using 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;
namespace Silverlight20.Data
{
public partial class ListBox : UserControl
{
public ListBox()
{
InitializeComponent();
BindData();
}
void BindData()
{
var source = new Data.SourceData();
// 设置 ListBox 的数据源
ListBox1.ItemsSource = source.GetData();
}
}
}
OK
Tags:Silverlight 数据 详解
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接