I'm a new in WPF. I have created a ListBox
<ListBox
Name="listBoxQuestion"
Grid.Row="1" Margin="3"
SelectionMode="Single"
MouseDown="listBoxQuestion_MouseDown"
SelectionChanged="listBoxQuestion_SelectionChanged"
DisplayMemberPath="Text">
</ListBox>
and I use listBoxQuestion.SelectedIndex to get index of selected item. But it only work once, the first time I click on item. When I click on other item, the index isn't changed. It still keep current value. I can't find what's wrong in my code. Please help me!
Update
There are my itemsource
public class ListTopicBinding : ObservableCollection<Question>
{
}
ListQuestionBinding listQuestionShowing = new ListQuestionBinding();
listBoxQuestion.ItemsSource = listQuestionShowing;
When I create new item I use code
Question q = new Question();
q.Text = "*";
listQuestionShowing.Add(q);
I have found that when I delete function in Question class
public override int GetHashCode()
{
return this.Text.GetHashCode();
}
My ListBox work correctly. I wonder that how "GetHashCode" func affect ListBox in WPF. I used this code in WinForm, but nothing happened. Sorry for my English