我想動態構建一個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」來訪問變量 –