C# 如何从对象中获取元素?
我在 WPF 中使用 AutoCompleteBox,使用包含四个字段的列表填充建议。当用户选择一个项目并且我到达我的 eventHandler 时,我可以看到这
MyAutoCompleteBox.SelectedItem
是一个具有四个值的对象,如果我将此文本悬停在调试器中,我可以看到列出的四个值,但是我不知道如何访问代码中的这些值。
我尝试了
List<Codes> selected = MyAutoCompleteBox.SelectedItem as List<Codes>;
代码是我的列表。 selected 每次都返回 null 和空。有没有办法获得这些值?谢谢!
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 my List. selected returns as null and empty every time. Is there a way to get to these values? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您希望将项目列表用作
AutoCompleteBox
的后备集合,请尝试...AutoCompleteBox.ItemsSource。If you want the listing of items used as the backing collection for the
AutoCompleteBox
try...AutoCompleteBox.ItemsSource.你可以尝试一下:
或者
Can you try:
or
这意味着您无法将任何 MyAutoCompleteBox.SelectedItem 转换为列表。
It means that you cannot convert whatever MyAutoCompleteBox.SelectedItem is to a List.