【发布时间】:2016-03-15 10:21:32
【问题描述】:
我正在尝试动态构建 AutoCompleteBox。然后我想在我的 itemsource 中使用客户列表,并且用户可视化 DescClient 字段。
List<Client> clients = ClientAction.getClientsFromUsers(Environment.UserName);
(field as AutoCompleteBox).ItemsSource = clients;
//CLIENT MEMBERS
private int idClient;
private string descClient;
private int idGroup;
private User user;
已经尝试过:
(field as AutoCompleteBox).ValueMemberPath = "DescClient"
但没有显示任何内容。我做错了什么会影响 ValueMemberPath 还是应该使用另一个 Proprety?
【问题讨论】:
-
您是否为客户成员定义了属性?
-
请注意,最好写
((AutoCompleteBox)field)而不是(field as AutoCompleteBox),因为如果field不是AutoCompleteBox,它会正确抛出InvalidCastException,而不是NullReferenceException。 -
是的,我有我的属性“DescField”来访问变量