C# 4.0 如何将列表数据绑定到combobox

C# 4.0 如何将列表数据绑定到combobox,c#-4.0,data-binding,silverlight-4.0,C# 4.0,Data Binding,Silverlight 4.0,我创建了一个包含以下方法的WCF服务: public List<LocationDB> GetLocation() { List<LocationDB> locations = null; using (SqlConnection connection = new SqlConnection(conn)) { using (SqlCommand command = new SqlCommand()) {

我创建了一个包含以下方法的WCF服务:

public List<LocationDB> GetLocation()
{
    List<LocationDB> locations = null;
    using (SqlConnection connection = new SqlConnection(conn))
    {
        using (SqlCommand command = new SqlCommand())
        {
            command.Connection = connection;
            command.CommandText = string.Format("Select L_ID ,L_Name from Location");
            connection.Open();
//code to fill the locations list..
最后是我的LocationDB类,它位于asp网站的App_code文件夹中:

     [DataContract]
public class LocationDB
{
    [DataMember]
    public int Lid { get; set; }
[DataMember]
public int SmId { get; set; }

[DataMember]
public string Lname { get; set; }
如何在代码隐藏而不是XAML中绑定SelectedValePath和DisplayMemberPath。
谢谢你,我可以告诉你,你所需要的东西都已经准备好了,尽管有些东西的顺序需要改变

void client_GetLocationCompleted(object sender, GetLocationCompletedEventArgs e)
{
    LocationCombo.SelectedValuePath = "Lid";
    LocationCombo.DisplayMemberPath = "Lname";
    LocationCombo.ItemsSource = e.Result;
}

您应该能够将它们中的每一个设置为一个字符串,该字符串表示要分别用作SelectedValuePath和DisplayMemberPath的属性(在绑定到的对象上):

LocationCombo.SelectedValuePath = "Lid";
LocationCombo.DisplayMemberPath ="Lname";
LocationCombo.ItemsSource = e.Result.ToList();
void client_GetLocationCompleted(object sender, GetLocationCompletedEventArgs e)
{
    LocationCombo.SelectedValuePath = "Lid";
    LocationCombo.DisplayMemberPath = "Lname";
    LocationCombo.ItemsSource = e.Result;
}
LocationCombo.SelectedValuePath = "Lid";
LocationCombo.DisplayMemberPath ="Lname";
LocationCombo.ItemsSource = e.Result.ToList();