获取 ListBox 中的 ListBoxItem [英] Get the ListBoxItem in a ListBox
本文介绍了获取 ListBox 中的 ListBoxItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当从 ListBox 中选择它时,我试图更改 ListBoxItem 上的 Control 模板.为此,我将从 ListBox 本身获取选定的 ListBoxItem,并在其上设置控件模板.我该怎么做呢?我已经尝试过 SelectedItem 并返回 ListBoxItem 中的绑定对象.
I am trying to change the Control template on a ListBoxItem when It is selected from the ListBox. To do so, I was going to get the selected ListBoxItem from the ListBox itself, and set the control template on that. How would i go about doing this? I have tried, SelectedItem and that returns the bound object within the ListBoxItem.
推荐答案
您可以使用 ItemContainerGenerator
从绑定的项目中检索项目容器:
You can retrieve the item container from the bound item by using the ItemContainerGenerator
:
object selectedItem = listBox.SelectedItem;
ListBoxItem selectedListBoxItem = listBox.ItemContainerGenerator.ContainerFromItem(selectedItem) as ListBoxItem;
这篇关于获取 ListBox 中的 ListBoxItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文