稳扎稳打Silverlight(3) - 2.0控件之Border, Button, Calendar, Canvas, CheckBox, ComboBox
[1] 稳扎稳打Silverlight(3) - 2.0控件之Border, Button, Calendar, Canvas, CheckBox, ComboBox
[2] 稳扎稳打Silverlight(3) - 2.0控件之Border, Button, Calendar, Canvas, CheckBox, ComboBox
[3] 稳扎稳打Silverlight(3) - 2.0控件之Border, Button, Calendar, Canvas, CheckBox, ComboBox
[4] 稳扎稳打Silverlight(3) - 2.0控件之Border, Button, Calendar, Canvas, CheckBox, ComboBox
[2] 稳扎稳打Silverlight(3) - 2.0控件之Border, Button, Calendar, Canvas, CheckBox, ComboBox
[3] 稳扎稳打Silverlight(3) - 2.0控件之Border, Button, Calendar, Canvas, CheckBox, ComboBox
[4] 稳扎稳打Silverlight(3) - 2.0控件之Border, Button, Calendar, Canvas, CheckBox, ComboBox
系列文章导航:
稳扎稳打Silverlight(1) - 1.0实例之电子表
稳扎稳打Silverlight(2) - 1.0实例之支持录音和回放的钢琴(Silverlight+ASP.NET AJAX+DLINQ)
稳扎稳打Silverlight(3) - 2.0控件之Border, Button, Calendar, Canvas, CheckBox, ComboBox
6、ComboBox.xaml
<UserControl x:Class="Silverlight20.Control.ComboBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left">
<!--
XAML方式构造ComboBox
-->
<ComboBox x:Name="cbo" Width="200" Margin="5">
<ComboBoxItem Content="ComboBoxItem1" />
<ComboBoxItem Content="ComboBoxItem2" />
<ComboBoxItem Content="ComboBoxItem3" />
</ComboBox>
<!--
后台邦定方式构造ComboBox
DisplayMemberPath - 数据源中需要被显示出来的字段名称
MaxDropDownHeight - 下拉框的最大下拉高度
-->
<ComboBox x:Name="cbo2" DisplayMemberPath="Name" MaxDropDownHeight
="100" Width="200" Margin="5" />
</StackPanel>
</UserControl>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left">
<!--
XAML方式构造ComboBox
-->
<ComboBox x:Name="cbo" Width="200" Margin="5">
<ComboBoxItem Content="ComboBoxItem1" />
<ComboBoxItem Content="ComboBoxItem2" />
<ComboBoxItem Content="ComboBoxItem3" />
</ComboBox>
<!--
后台邦定方式构造ComboBox
DisplayMemberPath - 数据源中需要被显示出来的字段名称
MaxDropDownHeight - 下拉框的最大下拉高度
-->
<ComboBox x:Name="cbo2" DisplayMemberPath="Name" MaxDropDownHeight
="100" Width="200" Margin="5" />
</StackPanel>
</UserControl>
ComboBox.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.Control
{
public partial class ComboBox : UserControl
{
public ComboBox()
{
InitializeComponent();
BindData();
}
void BindData()
{
var source = new Data.SourceData();
// 设置 ComboBox 的数据源
cbo2.ItemsSource = source.GetData().Take(10);
}
}
}
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.Control
{
public partial class ComboBox : UserControl
{
public ComboBox()
{
InitializeComponent();
BindData();
}
void BindData()
{
var source = new Data.SourceData();
// 设置 ComboBox 的数据源
cbo2.ItemsSource = source.GetData().Take(10);
}
}
}