我有一个包含以下实体的模型: USERS (LINK(主键),DEP_LINK(链接到DEPARTMENTS),....) DEPARTMENTS (链接,标题,......) 我想实现一个Login窗口,我需要在ComboBox中显示所有用户。我的ComboBox看起来像这样:
<ComboBox Height="23" Margin="66,87,65,0" Name="cmbUsername" VerticalAlignment="Top"
SelectedItem="{Binding SelectedUser}" ItemsSource="{Binding Usernames}"
DisplayMemberPath="LINK"/>
我的ViewModel如下所示:
private RSDBEntities dataContext;
public USERS SelectedUser { get; set; }
public List<USERS> Usernames { get; set; }
public AuthorizationViewModel()
{
dataContext = new RSDBEntities();
Users = new ObservableCollection<USERS>(dataContext.USERS);
LoginCommand = new RelayCommand(Login);
Usernames = dataContext.USERS.ToList();
}
所以我的问题是如何在ComboBox中显示DEPARTMENTS标题?我试图将DisplayMemberPath属性设置为'DEPARTMENTS'或'TITLE',但无法获得预期的结果。