我想动态构建一个AutoCompleteBox。然后我想在我的项目源中使用客户端列表,并且用户可视化DescClient字段。绑定到ItemSource
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?
您是否为客户成员定义了属性? – Domysee
只需注意,你应该更好地写'(((AutoCompleteBox)field)'而不是'(field as AutoCompleteBox)',因为如果'field'不是AutoCompleteBox,它会正确地抛出一个InvalidCastException,而不是NullReferenceException。 – Clemens
是的,我有我的propretie“DescField”来访问变量 –