-2

I'm trying to build dynamically a AutoCompleteBox. Then I want to use a list of Clients in my itemsource, and the user visualize the DescClient field.

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;

Already tried like:

(field as AutoCompleteBox).ValueMemberPath = "DescClient"

But doesn't show anything. Am I doing something wrong afecting the ValueMemberPath or should I use another Proprety?

Tseng
  • 61,549
  • 15
  • 193
  • 205
Andre Roque
  • 503
  • 1
  • 9
  • 31
  • Do you have properties defined for the client members? – Domysee Mar 15 '16 at 10:37
  • 3
    Just a note, you should better write `((AutoCompleteBox)field)` instead of `(field as AutoCompleteBox)`, because in case `field` is not an AutoCompleteBox it would correctly throw an InvalidCastException, instead of a NullReferenceException. – Clemens Mar 15 '16 at 10:41
  • Yes I have my propretie "DescField" to access the variable – Andre Roque Mar 15 '16 at 10:54

1 Answers1

1

As stated here you can use ItemTemplate (there's also a reference on how to create DataTemplate from code, if you need it).

here a guide on AutoCompleteBox from Jeff Wilcox website.

Community
  • 1
  • 1
Marco
  • 744
  • 6
  • 14
  • I tried that approach, creating my user control with the bindings, but it stays the same – Andre Roque Mar 15 '16 at 11:27
  • Right now the list is returning me not the DescField but the full name of Client .Client I guess I'm missing some atribute to display only that field – Andre Roque Mar 15 '16 at 11:31
  • Already worked! I had to add ValueMemberPath="DescClient" to controls:AutoCompleteBox. thanks a lot – Andre Roque Mar 15 '16 at 11:38