在Combobox中显示数据(Windows 8.1 / XAML)

时间:2015-01-19 08:48:41

标签: c# xaml combobox windows-8.1

这是我的问题:我有2个班级

 public class UserProfile 
{
    public int UserId { get; set; }
    public string UserName { get; set; }

    public string Email { get; set; }


    public string Password { get; set; }
    public string PasswordSalt { get; set; }

    public string ConfirmPassword { get; set; }

    public byte[] Photo { get; set; }

    public string Location { get; set; }

    public string FirstName { get; set; }

    public string LastName { get; set; }

    public virtual University University { get; set; }
    public int UniversityId { get; set; }

}

 public class University 
{
    public int UniversityId { get; set; }

    public string NameUniversity { get; set; }

    public string MailUniversity { get; set; }

    public string AddressUniversity { get; set; }

    public string Location { get; set; }

    public virtual ICollection<UserProfile> Users { get; set; }
}

注册(添加关于数据库的信息)我想在组合框中显示大学列表以允许用户选择他的大学,但我不知道如何在组合框中进行绑定(XAML和代码后面)。

有人有想法吗? 谢谢

1 个答案:

答案 0 :(得分:0)

<Grid>
  <StackPanel>
    <Button Click="Button_Click">asdf</Button>
    <ComboBox ItemsSource="{Binding Path=PhonebookEntries}"
              DisplayMemberPath="Name"
              SelectedValuePath="Name"
              SelectedValue="{Binding Path=PhonebookEntry}" />
</StackPanel></Grid>

Binding WPF ComboBox to a Custom List.It is well explained