0

我有一个包含以下实体的模型:USERS (LINK (primary key), DEP_LINK (link to DEPARTMENTS), ....) DEPARTMENTS (LINK, TITLE, ....) 我想实现一个登录窗口,我需要在 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”,但无法获得预期的结果。

4

0 回答 0