WPF Listbox:如何获取绑定到ListBoxItem的数据 [英] WPF Listbox: How to get data bound to ListBoxItem

查看:764
本文介绍了WPF Listbox:如何获取绑定到ListBoxItem的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello CodeProject!

我正在学习WPF,现在我已经将DVD收藏集数字化,并希望将它们列出在我的ListBox中.单击它们应该给我DVD的详细信息(主详细视图).
现在我的问题是:如何在Code-Behind中检索绑定到所选ListBoxItem的数据?我想我必须使用SelectionChangedEvent,但是如何访问数据而不是ListBoxItem?

谢谢!

Hello CodeProject!

I''m learning and learning WPF and now I have digitalised my DVD collection and wanted to list them up in my ListBox. Clicking on them should give me the details of the dvd (master-detail-view).
Now my question is: How can I retreive the data bound to the selected ListBoxItem in Code-Behind? I think I have to use the SelectionChangedEvent, but how do I access the data and not the ListBoxItem?

Thanks!

推荐答案

好,我自己找到了解决方案:
我使用e.AddedItems [0]并将其投射.

OK, I found the solution myself:
I use e.AddedItems[0] and cast it.

private void MixControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
   //MessageBox.Show(e.AddedItems[0].ToString());
   Mix mix = (Mix)e.AddedItems[0];
}


这篇关于WPF Listbox:如何获取绑定到ListBoxItem的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆