开发学院图形图像Flash Silverlight(17) - 2.0数据之详解DataGrid, 详解L... 阅读

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

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

上一页  2 3 4 5 6 7 

Tags:Silverlight 数据 详解

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接