I have a listbox in my silverlight usercontrol and I am filling it with a generic list of a private class, for some reason it is not being databound.
Here is the code :
class userClient
{
public int characterID { get; set; }
public string characterName { get; set; }
}
List<userClient> userClientList; // = new List<userClient>();
void _client_UserList(object sender, DataTransferEventArgs e)
{
this.Dispatcher.BeginInvoke(() =>
{
userClientList = new List<userClient>();
foreach (string user in e.DataTransfer.Data)
{
var userDetailsArray = user.Split('+');
userClient uc = new userClient
{
characterID = Convert.ToInt32(userDetailsArray[0]),
characterName = userDetailsArray[1]
};
userClientList.Add(uc);
}
chatUsers.ItemsSource = userClientList;
chatUsers.DisplayMemberPath = "characterName";
});
}
I checked the generic list userClientList
and it is being filled up so there is no problems there.
This is the XAML of the listbox:
<ListBox x:Name="chatUsers" Grid.Row="0" Grid.Column="1" Margin="2 2 2 2" />