silverlight 数据库数据读出来怎么绑定到combobox 5

 我来答
尉迟丶九方
2012-01-20 · TA获得超过148个赞
知道小有建树答主
回答量:158
采纳率:0%
帮助的人:186万
展开全部
给你个例子,觉得好就采纳吧
public class LocationRoad
{
public int ID { set; get; }
public string Code { set; get; }
public string Info { set; get; }
}

  类的集合:
/// <summary>
/// 当ComboBox选中项更改时发生
/// </summary>
private LocationRoad _selectLocation;
public LocationRoad SelectLocation
{
get { return this._selectLocation; }
set
{
this._selectLocation = value;
if (this.PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("SelectLocation"));
}
}
private ObservableCollection<LocationRoad> _locationRoad = null;
public ObservableCollection<LocationRoad> LocationSource
{
get
{
if (this._locationRoad == null)
{
this._locationRoad = new ObservableCollection<LocationRoad>()
{
new LocationRoad() { ID = 1, Code = "NGQ", Info = "南岗区" },
new LocationRoad() { ID = 2, Code = "DLQ", Info = "道里区" },
new LocationRoad() { ID = 3, Code = "DWQ", Info = "道外区" },
new LocationRoad() { ID = 4, Code = "PFQ", Info = "平房区" },
new LocationRoad() { ID = 5, Code = "XFQ", Info = "香坊区" },
};
}
return this._locationRoad;
}
set
{
this._locationRoad = value;
if (this.PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("LocationSource"));
}
}
  前台XAML文件绑定方式:

<ComboBox Margin="-16,3,0,5" Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="2" Name="cboxLocationKeyword"
ItemsSource="{Binding LocationSource,Mode=OneWay}"
SelectedValuePath="ID"
DisplayMemberPath="Info"
SelectedItem="{Binding SelectLocation}" />
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式