silverlight 数据库数据读出来怎么绑定到combobox 5
1个回答
展开全部
给你个例子,觉得好就采纳吧
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}" />
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}" />
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询