在列表框中选择一个文本框项目不会更改列表框中的所选项目 [英] Selecting a Textbox Item in a Listbox does not change the selected item of the listbox
本文介绍了在列表框中选择一个文本框项目不会更改列表框中的所选项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个wpf列表框,它显示文本框的列表.当我单击文本框时,列表框选择不会更改.我必须单击文本框"旁边的以选择列表框项.我需要为文本框设置一些属性,以将click事件转发到列表框吗?
I Have a wpf Listbox that display's a list of textboxes. When I click on the Textbox the Listbox selection does not change. I have to click next to the TextBox to select the listbox item. Is there some property I need to set for the Textbox to forward the click event to the Listbox?
推荐答案
我们使用以下样式来设置一个PreviewGotKeyboardFocus,以处理TextBox控件和ComboBoxes等所有事件:
We use the following style to set a PreviewGotKeyboardFocus which handles all events of TextBox control and ComboBoxes and such:
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<EventSetter Event="PreviewGotKeyboardFocus" Handler="SelectCurrentItem"/>
</Style>
</ListView.ItemContainerStyle>
然后我们选择后面代码中的行:
And then we select the row in code behind:
protected void SelectCurrentItem(object sender, KeyboardFocusChangedEventArgs e)
{
ListViewItem item = (ListViewItem) sender;
item.IsSelected = true;
}
这篇关于在列表框中选择一个文本框项目不会更改列表框中的所选项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文