How to get elements from an object in C#?
I am using the AutoCompleteBox in WPF, I populate the suggestions with a List that consists of four fields. When the user selects an item and I reach my eventHandler, i can see that
MyAutoCompleteBox.SelectedItem
is an object that has my four values, if i hover this text in the debugger i can see the four values listed, however i don't know how to access these values in the code.
I tried
List<Codes> selected = MyAutoCompleteBox.SelectedItem as List<Codes>;
where Codes is m开发者_开发百科y List. selected returns as null and empty every time. Is there a way to get to these values? Thanks!
If you want the listing of items used as the backing collection for the AutoCompleteBox
try...AutoCompleteBox.ItemsSource.
Can you try:
Codes selected = MyAutoCompleteBox.SelectedItem as Codes;
or
Codes[] selected = MyAutoCompleteBox.SelectedItem as Codes[];
It means that you cannot convert whatever MyAutoCompleteBox.SelectedItem is to a List.
精彩评论