wpf ListBox绑定数据后如何获得ListBoxItem

xeonfeng xeonfeng 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
绑定数据的Listbox如何获取到当前选中的ListBoxItem,如下代码获取到的是VedioScreen的实体。
请教如何获取当前选中的listboxItem项?

XAML:
<ListBox x:Name="PlayListBox" ItemsSource="{Binding VedioScreenList,Mode=TwoWay}" 
SelectedItem="{Binding VedioScreenItem}" SelectionMode="Single"
ItemContainerStyle="{StaticResource ListBoxItemStyle}"
SelectionChanged="PlayListBox_SelectionChanged" />


C#:
 void PlayListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
VedioScreen vs = PlayWndListBox.SelectedItem as VedioScreen;
var lstitem = (sender as ListBox).SelectedItem as ListBoxItem; //这里lstitem是null
}
...全文
评论 7
收藏 已收藏
分享
返回顶部
xeonfeng
C# 111,129 成员 642,538 内容